Highlight Menu Item for Custom Post Types

If you’ve ever added a custom link to a WordPress menu item that directs to a custom post type archive, you’ve probably been dismayed at the fact that the highlighting classes such as “current_page_item” aren’t added for you and even worse, “current_page_parent” is added to the menu item for the page that displays your recent blog posts. Here’s a quick snippet that will help you get the desired class structure:

Hi Tammy, great stuff! I’m learning a lot from your tuturials. I’ve included this code in my plugin but $item->url returns as string consisting of all the url’s of the menu pasted together, so the ‘current_page_item’ class is not added.
Sorry for the noob question, teaching myself as I go along.
best,
Demu

So basically, this asks if we’re current on a page that is either a custom post type or its archive. Next it removes the “current” class from the item. Then it says, but hey, if the current menu item is a URL to the custom post type’s slug, add that “current” class back in.

So what you need to do is change the conditional from a post type to a taxonomy and make sure the slug you’re looking for is the one for the taxonomy.