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

For example:-

    Apple (3)
    ball (6)
    cat (2)
  • What exactly is this? Categories? Post Tags? Custom Taxonomy terms? Highly depends on what count you want to show.
    – kaiser
    May 23, 2013 at 8:19

2 Answers 2


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;

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;
  • 1
    Yes i saw it. Now i checked again. I think its not post count. It's menu count.
    – Sibiraj PR
    May 23, 2013 at 7:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.