WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to add post count to menu links using wp_nav_menu?

For example:-

    Apple (3)
    ball (6)
    cat (2)
share|improve this question
What exactly is this? Categories? Post Tags? Custom Taxonomy terms? Highly depends on what count you want to show. – kaiser May 23 '13 at 8:19
up vote 2 down vote accepted

Basically the easiest thing should be a callback to the start_el() method of the Walker class.

// From core:
apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );

Just grab the data (whatever the actual data is and from wherever it comes) and append it.

add_action( 'walker_nav_menu_start_el', 'wpse_10042_nav_menu_post_count', 10, 4 );
function wpse_10042_nav_menu_post_count( $output, $item, $depth, $args )
    // Check $item and get the data you need
    printf( '<pre>%s</pre>', var_export( $item, true ) );
    // Then append whatever you need to the $output
    $output .= '';

    return $output;
share|improve this answer

Have you seen this thread?

$menu_to_count = wp_nav_menu(array(
    'echo' => false,
    'theme_location' => 'menu'
$menu_items = substr_count($menu_to_count,'class="menu-item ');
echo $menu_items;
share|improve this answer
Yes i saw it. Now i checked again. I think its not post count. It's menu count. – Sibiraj PR May 23 '13 at 7:37
Oh shit, sorry! – Richard B May 23 '13 at 7:43
NOP. Thank you for looking here. – Sibiraj PR May 23 '13 at 7:46

Your Answer


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.