Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This solution does almost what I want it to.

Only thing is, I have my menu set up as follows:

Menu item 1
Menu item 2
   Custom post type 1
   Custom post type 2
   Custom post type 3
Menu item 3

Using the solution I mention adds the tag "current_url" to the sub menu of the custom post type I'm in ("Custom post type 1"). But I want it to add a "current_menu_item" (or something) to "Menu item 2".

Any way to do this?

share|improve this question
    
Possible duplicate - does this do what you desire? My solution adds a current-sub class to all sub-menus that are ancestors of the current-menu-item (and/or other menu-item classes). –  boscho Jan 22 at 22:04
add comment

2 Answers 2

WordPress handles this by adding the current_page_ancestor and/or current_page_parent class to the parent item. Try styling those classes similar to current_menu_item.

share|improve this answer
1  
there are no current tags of any kind to the "main menu item". Which is what I'm trying to find a solution for. I'm assuming it's because I'm using a custom post type. –  Lisa Jul 24 '12 at 18:12
    
are the custom post type links, custom links? –  Joshua Abenazer Sep 7 '12 at 10:11
    
If you are linking to custom post type archives via a custom link, then WordPress doesn't add any current or ancestor classes. This is a known bug, and there's already a ticket on Trac. –  Fränk Aug 5 '13 at 6:56
add comment

I do the following, it can be lengthy if you have many post types, feel free to edit it however:

/** Edit Nav Menu calsses **/
function custom_wp_nav_classes($classes, $item){
    global $post;
    $page_blog = get_option('page_for_posts');

    if(is_tax('my_taxonomy_name_here') || is_singular('my_post_type_name_here')){

        /** Remove Active Class from Blog **/
        if($item->object_id == $page_blog)
            $classes = array_filter($classes, "remove_parent");

        /** Page ID of what you want to be active **/
        if($item->object_id == 12)
            $classes[] = 'current_page_parent';
    }

    return $classes;
}
add_filter('nav_menu_css_class' , 'custom_wp_nav_classes' , 10 , 2);

// Remove Active Class from Blog when viewing CPTs
function remove_parent($var){
    if ($var == 'current_page_parent' || $var == 'current-menu-item' || $var == 'current-page-ancestor') { return false; }
    return true;
}
share|improve this answer
add comment

Your Answer

 
discard

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.