WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

TwentyTen adds some classes to custom menus, for instance:

#access #menu-item-262.current-menu-item, #access #menu-item-262.current-menu-ancestor

All the top-level links in my primary navigation have the class .current-menu-ancestor when the user is on a child page -- except when I'm viewing content in the custom post type I've built.

How do I set the current page in navigation when viewing a custom post type?


share|improve this question
up vote 2 down vote accepted

The classes are not added by the Twenty Ten theme, but by the common custom navigation menu code, in _wp_menu_item_classes_by_context(), which is called from wp_nav_menu().

If you want to add extra classes you can do that by either hooking into wp_nav_menu_objects, called once with the whole menu tree, or into nav_menu_css_class, called when rendering each individual item.

share|improve this answer
Awesome, perfect answer. Thank you! – aendrew May 4 '11 at 10:19

I figured this out as I was typing out the answer.

If you have the line: <body <?php body_class(); ?>> in your header.php for your body tag, custom post templates will each have their own body class. Because in my case all content in that custom post type is under one section of my navigation bar, I was able to simply add the body class before the declaration, i.e., .single-film #menu-item-262 where "film" is the name of my custom post type.

That said, this solution won't work for sites where custom post types reside under different parts of the navigation. Is there a better way to go about this than I did?


share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.