I believe this doesn't happen very often. I am working on a project in which a child page can show up under several different parent pages.

The page actually belongs to just one parent, but in the main navigation it needs to show up under two or more parents. Don't ask me why, people like to be redundant.

I am using wp_nav_menu to create the main navigation.

My structure is:

Parent A - child 1 - child 2

Parent B - child 1 - child 2 - child 3 (this child is the same as Parent A Child 2)

Parent C - child 1 - child 2 (this child is the same as Parent A Child 2 and Parent B Child 3) - child 3

I normally use the classes current-menu-ancestor current-menu-parent to highlight the navigation because they typically only show in one <li> , but because some children are listed several times under different parents, those classes are no longer unique to the page. So I ended up with two or more highlighted items. All other classes are also exactly the same in this case. There's not one unique class to select.

Has anyone run into a similar issue? I can only fix this by using javascript, comparing ID and then unhighlighting the wrong ones. But I was wondering if there's a wordpress solution (filters) or a css solution.

1 Answer 1


A filter solution could be the nav_menu_css_class filter. A CSS solution could be to use the body_class to make more specific css rules.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.