Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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