Highlight menu item when on a custom post type?

If this is for a one-off site, I would suggest doing this with CSS. Philosophically, adding the current_page_item class to a menu item when that’s not true feels a bit wrong too.

As long as you’re using the body_class() function on your <body> element in the theme, there should be a class called single-{event} where “{event}” is the id of the post type. Hence, add the selector .single-{event} .page-item-{ID} where “{ID}” is the page ID of the events page (you’ll see that as the class on the menu item as well).

Leave a Comment