I don’t know why the proper classes for menu item are not generated – all the elements in the tree which has subtree get only menu-item menu-item-type-post_type
. The elements, which don’t have children, get proper classes after being clicked (active).
Link: http://lichens.ie/
Part of the menu structure: http://imgur.com/5Lj00.png
Code
$args = array(
'menu' => 'Main menu',
'container' => '',
'menu_id' => 'nav',
);
wp_nav_menu($args);
When you visit e.g. http://lichens.ie/view-lichens-by/lichens-by-habitat/ you can see that it has no ‘current’ class. As well as it’s parent.
PS Sorry for posting ‘not working links’ – it’s because of reputation limitation
Any ideas – help much appreciated.
This is part of code in
_wp_menu_item_classes_by_context()
that handles current class for pages:post_type
type.is_singular
.Second point can be excluded, because CSS class for item type is generated correctly. So something goes wrong either with IDs or
is_singular
conditional.Are you running any secondary loops on page? Most common reason for conditionals to break is improper use of
query_posts()
.I don’t know why its not working in your case… Like you say, the active page should be getting ‘current_menu_item’ added to its classes. If you’re having trouble for one reason of another, you can always use the ‘nav_menu_css_class’ filter to add your own classes. This little bit of code will essentially duplicate the ‘current_menu_item’ & ‘current_menu_parent’ classes, and add a ‘has_children’ class (useful for expandable or dropdown menus):
Of course you want to figure out why the built-in functionality isn’t working for you before hacking up something to duplicate it, but you can do a lot with that filter if necessary…