OK so i have a main menu and a sub-menu
How can i make a menu item active when viewing a single post.
The sub-menu uses taxonomies so i know i need to make the taxonomy active when one of the posts has the taxonomy in use
OK so i have a main menu and a sub-menu
How can i make a menu item active when viewing a single post.
The sub-menu uses taxonomies so i know i need to make the taxonomy active when one of the posts has the taxonomy in use
You must be logged in to post a comment.
I did something similar with highlighting current category in navbar, you can see my answer here. The hook of course won’t work for you, I think a better hook would be ‘nav_menu_css_class’
So i ended up doing some jquery and lots of it. The downside is that i have to add the code each time i create a new menu. I am looking into re-creating this but do not want to bother with it right now. This is the link to the solution. It is very very temporary so if you wish to use it go ahead but there are better ways. You may be able to hook into the wp_nav_menu classes and add a active class to the current active item and then use some jquery to finish it off.
You can check the slug and and the current taxonomy against one another.
For example if you were outputting a menu using
get_terms($taxonomy)
you could use an if statement to check whether the current page’s taxonomy is the same as the slug menu item and give it an active class.Where discipline is your custom taxonomy.
have a read of this codex: http://codex.wordpress.org/Dynamic_Menu_Highlighting