Hi, I have a menu with 3 or 4 levels. I see there is a “current-menu-parent” class that gets added to the current menu parent, but I also need classes that go all the way up to the top level items, for example “current-menu-grandparent” and “current-menu-greatgrandparent” or even just a simple class all the way through that shows as “current-menu”. How can I get this sort of class or classes to show?
Need “current” classes up navigation tree
Resolved
OnPoint Plugins
Hi Mary,
It sounds like the class you are looking for is “current-menu-ancestor”. This class will be available on every level of the menu above the current item.
If you are not seeing this class, please let us know and provide a link to where we can see the menu.
Have a great day!
Mary Walsh
I believe so, but no I don’t see this class. I’m expecting to see this on the “News” top level item on this page:
OnPoint Plugins
Hi Mary,
I was able to track the issue down. This is what is happening:
Because the current post is not part of the menu, WP does not assign ancestor classes to any menu items.
You may add the following filter to your active theme’s functions.php file to include the “current-menu-ancestor” class on parent/grandparent menu items which meet this criteria:
Have a great day!