.IsMenuCurrent returns false for single pages

I had exactly the same problem. .IsMenuCurrent and .HasMenuCurrent are not working on kind page. So if my menu states an about-page (kind: page) which I then visit, I would expect it to get the “is-active” class. But this is not happening.

If I understand the source code correct, it is intended, because both function have:

if p.IsPage() {
    return false
}

The documentation is indeed not very helpful in this matter. For me, it was an unexpected behavior. Maybe it should also work for kind pages to improve ux. For the .IsMenuCurrent I used this workaround:

{{ $currentPage := . }}
{{ range .Site.Menus.main }}
    <li class="{{ if eq $currentPage.URL .URL }}is-active{{ end }}">...</li>
{{ end }}
4 Likes