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

  • What does the main menu show?
    – Lea Cohen
    Commented May 9, 2011 at 5:21
  • shows home movies music sub-menu for movies is action adventure drama etc and music is rock hiphop country metal etc Commented May 9, 2011 at 5:41
  • but i need the sub menu highlited not the main. i already have code in place when viewing the sub-menu items but need to code when a post is active Commented May 9, 2011 at 5:42
  • So can anyone else help me Commented May 10, 2011 at 0:54
  • Could you show the code with which you create the sub menu that shows the the taxonomies? And another thing - if a post has more than one tag, you want all the tags that it has to be highlighted?
    – Lea Cohen
    Commented May 10, 2011 at 17:01

4 Answers 4


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'

  • Sorry i havent been able to try this yet. I have had some other problems happen with my site and they need priority. When i get a change ill post back. Commented May 13, 2011 at 1:20
  • I dont think this is going to work as there are some things that are for categories and i tried changing them out and that did not work Commented May 17, 2011 at 22:44
  • I could not get it to work but i did use this on another project. So ill mark as answered Commented May 21, 2011 at 18:23
  • @xLRDxREVENGEx - thank you, that's very kind of you. Although it might be misleading to mark as answered a question that you still need an answer for... Maybe just up upvote (if you want)? Or nothing?
    – Lea Cohen
    Commented May 21, 2011 at 21:20

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.

                $taxonomy = 'disciplines';
                $tax_terms = get_terms($taxonomy);
                $current_taxonomy = get_query_var($wp_query->query_vars['taxonomy']);
                foreach ($tax_terms as $tax_term) {

                    if ($current_taxonomy == $tax_term->slug) {
                        $active = 'active';

                    echo '<li class="filter ' . $active . ' clearfix"><a href="/disciplines/' . $tax_term->slug . '"><i class="fa fa-circle-o"></i><i class="fa fa-circle"></i> ' . $tax_term->name . '</a></li>';

                    $active = "";

Where discipline is your custom taxonomy.


have a read of this codex: http://codex.wordpress.org/Dynamic_Menu_Highlighting

  • Have read it but will not do what i want. The default core setup highlights categories not tags Commented Jun 13, 2011 at 20:27
  • Link only answers contribute nothing. Besides, link is now dead. Commented Mar 9, 2019 at 3:21

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.