Set menu active state for custom posttype and category, given custom taxonomy term

How to set the menu active state for a custom posttype and category, given a custom taxonomy term?

I have a custom taxonomy: region, a custom posttype: business, and use the categories taxonomy. My custom primary menu consists of the region terms.

Read More

When I select a region, the corresponding menu item is highlighted OK. The region page shows a listing of relevant categories. Now, when I select a category on this page the corresponding menu item is not highlighted. In turn, the category page shows a listing of businesses. Also, when I click on a business, the corresponding menu-item is not highlighted.

So, how to set the menu active state on a category page and on a business post, given a custom taxonomy term? I do have a session variable region available on these pages.

Related posts

Leave a Reply

2 comments

  1. When you create a custom menu item for the custom post type archive you have to include the entire url and not just /your-custom-post-type-name. If you use the entire url the wordpress url rewrite function will check it against all the other menu items as well as against all your pages and so on. What you end up with in the menu parent is something like current-menu-ancestor current-menu-parent current_page_parent current_page_ancestor.

  2. You probably can do this via CSS. As the body has classes lined up depending on the page that is displayed and the menu entries have classes and ids on their own, you can probably hardcode the highlight into custom CSS.

    If the highlighting is done with markup instead of CSS then this is not possible. But I think that is not the case.

    So inspect (e.g. with Firebug) the body tag on those pages and check for the ids of the menu items. Next to that you can check how the highlighting is done with Firebug.

    The rest should be copy and paste.