• I have some pages that appear multiple times in my custom menu. I’m finding that when I navigate to these pages, all menu parent items are getting the current-menu-ancestor and current-menu-parent classes added, therefore multiple parent menu items are highlighted.

    To combat this I’m using jquery in these pages individual templates to remove the classes from the menu.

    Surely there’s a simpler way? I would have thought WP could detect which menu item you’ve clicked and only apply the class to that menu parent, rather than all the parents that have that page as a menu child getting highlighted?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    How does your jQuery know which child menu item was chosen?

    Thread Starter cokeyblokey

    (@cokeyblokey)

    it doesn’t – all it does is remove the classes from particular menu items:

    jQuery("li#menu-item-15, li#menu-item-409").removeClass("current-menu-ancestor current-menu-parent");

    the code only exists in the individual page template I use for that particular page – the page that appears in multiple menu places.

    It’s not ideal as it means that no menu item has ‘current’ applied when the page is visited but it’s better than having both parent menu items highlighted!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Preventing multiple menu items getting 'current' class’ is closed to new replies.