Skip to content

Instantly share code, notes, and snippets.

@Roy-Oto
Created May 10, 2021 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Roy-Oto/26ee226c4001479b0f1cce6bf122189c to your computer and use it in GitHub Desktop.
Save Roy-Oto/26ee226c4001479b0f1cce6bf122189c to your computer and use it in GitHub Desktop.
How to display the number of items in a category (normal)
add_filter('wp_nav_menu_objects','my_nav_count');
function my_nav_count($items){
foreach ($items as $item){
if($item->object == 'category'){
$item->title .= " (". get_term($item->object_id,'category')->count .")";
$args[] = $item;
}
}
return $args;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment