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.

I search in Internet but i didn't find a good documented way how to add to item from menu a number , my current menu is like

Item1
Item2
Item3 ,

I'm calculating with WP_Query how many post for category i have , and within function to update a specific menu item like :

Item1(10) 
Item2(5) 
Item3(20)

Thank you a LOT ! :)

i finded a solution , but i don't know how to filter by specific menu , location

function wpa_filter_nav_menu_objects( $items){

foreach( $items as $item ){

    if( strtolower($item->title)=='sample page' ){
        $item->title = $item->title.'(10)';
    }
}
return $items; } add_filter( 'wp_nav_menu_objects', 'wpa_filter_nav_menu_objects' );

menu i'm creating in admin panel , from Apperance > Menus

Thank you again !

share|improve this question
    
Can you add more detail to your question? –  Jake Lisby Jul 5 '13 at 21:34
    
In order to get valuable help you have to provide us with your current code. There are multiple ways to generate a list/menu... –  t f Jul 5 '13 at 21:52

1 Answer 1

You can target the location like this:

function wpa_filter_nav_menu_objects( $items, $args ){
    if( $args->theme_location === 'primary' ){
        foreach( $items as $item ){
            if( strtolower( $item->title ) === 'sample page' ){
                $item->title = $item->title . '(10)';
            }
        }
    }
    return $items;
}
add_filter( 'wp_nav_menu_objects', 'wpa_filter_nav_menu_objects', 10, 2 );

You can also try $args->menu_id if you use that input parameter.

share|improve this answer
    
sorry but $args , i tried but is not working , thank you for help !!! –  mIRU Jul 9 '13 at 10:29
    
ok, but this worked on my install, how do you call wp_nav_menu and what is the theme location? –  birgire Jul 9 '13 at 11:01

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.