adding .current* tags to custom post types and taxonomies

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?

Thanks…

2 Answers
2

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.

Leave a Comment