OnPoint Plugins

  • Plugins
    • Advanced Sidebar Menu
    • Go Live Update Urls
  • About
    • Services
    • Showcase
  • Blog
  • Contact
  • Support
  • Log In
← Back to support

Need “current” classes up navigation tree

Resolved

Requested: 3 months and 2 weeks ago

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?

Plugin: Advanced Sidebar Menu

  1. OnPoint Plugins

    3 months and 2 weeks ago

    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!

  2. Mary Walsh

    3 months and 2 weeks ago

    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:

  3. OnPoint Plugins

    3 months and 2 weeks ago

    Hi Mary,

    I was able to track the issue down. This is what is happening:

    1. The current post is not part of the menu.
    2. The “News Releases” menu item happens to be a category the current post is assigned to.
      1. WP core gives the current parent classes to assigned categories.
    3. The “News” menu item is a custom link which does not have any relation to posts nor categories.

    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:

    1. Category menu items (and possibly other similar types).
      1. If current post is assigned to this category.
    2. When the current post is not in the menu.

    Have a great day!

     

New Response Cancel reply

You must be logged in to respond. Only PRO members are allowed to respond to support requests.

© 2023 · WordPress Development · Terms Of Service · Privacy Policy · Cookie Policy · Log in

  • Plugins
  • Blog
  • Contact