Return to Snippet

Revision: 52509
at October 25, 2011 11:46 by inflightatnight


Initial Code
add_filter('nav_menu_css_class', 'current_type_nav_class', 10, 2 );
function current_type_nav_class($classes, $item) {
    $post_type = get_query_var('post_type');
    if ($item->attr_title != '' && $item->attr_title == $post_type) {
        array_push($classes, 'current-menu-item');
    };
    return $classes;
}

Initial URL
http://wordpress.stackexchange.com/questions/3014/highlighting-wp-nav-menu-ancestor-class-w-o-children-in-nav-structure

Initial Description
Add current class to single posts in Wordpres wp_nav_menu by adding a filter

Initial Title
Add Current Class To Single Posts in Wordpress Nav Menu

Initial Tags
php, wordpress, filter

Initial Language
PHP