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.

2 Answers
2

This is part of code in _wp_menu_item_classes_by_context() that handles current class for pages:

// if the menu item corresponds to the currently-queried post or taxonomy object
} elseif (
    $menu_item->object_id == $queried_object_id &&
    (
        ( ! empty( $home_page_id ) && 'post_type' == $menu_item->type && $wp_query->is_home && $home_page_id == $menu_item->object_id ) ||
        ( 'post_type' == $menu_item->type && $wp_query->is_singular ) ||
        ( 'taxonomy' == $menu_item->type && ( $wp_query->is_category || $wp_query->is_tag || $wp_query->is_tax ) )
    )
) {
    $classes[] = 'current-menu-item';
  1. IDs must match.
  2. It must be of post_type type.
  3. Query should be for 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().

Leave a Reply

Your email address will not be published. Required fields are marked *