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.

In my site i have a navbar which is created by using the new feature of wordpress 3 - "the menus ".In my site this navbar conatins both categories and pages.

When I'm in a single post / sub-page , the navbar doesn't give the parent category /page the class of "current-menu-item" and therefore that item in the navbar is not highlighted.

I found this but it really doesn't help me because the menu is not built on

category_ID like a regualr navbar created by wp_categories_list(), but on item_ID , which I don't understand how is generated.

I would like to know either how the item_ID is generated, and/or how to highlight the right item in the navbar

Here is a printscreen of my navbar's HTML

alt text

and here is a printscreen of navbar created by wp_categories_list()

alt text

thanks!!

share|improve this question
    
Is the current-menu-item or current-page-item class not what you're looking for? –  prettyboymp Dec 23 '10 at 13:35
    
You are seeking to highlight the top most parent element when the current page is direct descendent, correct? I'd like to know this answer to. OT: I wish WP did not add all those 'menu-item menu-item type-post_type' redundant classes! –  Scott B Dec 23 '10 at 16:22
add comment

2 Answers

up vote 3 down vote accepted

The filter you need is nav_menu_css_classes. You should be able to test for *in_category* on single post and archive pages, and add the appropriate class there.

share|improve this answer
    
That feeling when I find my own answer from two years ago, and its wrong. Ugh. The filter is actually named nav_menu_css_class. –  goldenapples Oct 19 '12 at 20:51
add comment

You can style this classes,

"current-cat" "current-menu-item" "current-page-item"

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.