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.

Is there a way of manually specifying which page is currently "active" when using wp_nav_menu()?

I have a "Products" page, and on that page I have links to various (dynamic) custom taxonomies. When I click on one of these taxonomies, I stay on the "Products" page but wp_nav_menu() loses reference to that fact that I'm still on the "Products" page. Is there a way I can fix this?

Thanks!

Jon

share|improve this question

2 Answers 2

up vote 9 down vote accepted

If you just want to add the current_page_item class to one menu item, you could hook up to the nav_menu_css_class filter, and add that class if needed. It is called when the menu is printed.

If you want access to the whole menu and add classes, hook in to the wp_get_nav_menu_items filter, where you get the whole $items array. You can edit the classes properties of individual items.

share|improve this answer
    
Thanks Jan - great answer! –  Jon Sep 3 '10 at 9:46

@Jon As long as you are using <body <?php body_class(); ?>> WordPress will assign the class current_page_item to your menu along with current_page_parent if your using drop down menus.

share|improve this answer
1  
Hi Chris, Thanks for the reply. I am using the <body <?php body_class(); ?>> tag but the problem is that as far as the wp_nav_menu() is concerned the taxonomies im clicking on are unrelated to it! So, i need to say to wp_nav_menu() - if the page is X then show "Products" as the current_page_parent. –  Jon Sep 2 '10 at 9:39

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.