Hi argamassa,
There’s nothing built in to let you do this, so you’d need to use custom code. It looks like this code might work:
https://wordpress.stackexchange.com/questions/229767/show-posts-count-for-categories-and-tags-in-wp-nav-menu
Note you need to change the action name from
walker_nav_menu_start_el
to
megamenu_walker_nav_menu_start_el
Please note, as it’s custom code, it’s not something we cover through support, but hopefully this points you in the right direction. There are more options on google if you search for “wordpress show category count in menu items”.
Regards,
Tom
Thanks for your answer, please can you tell me where can I found the php file for apply the changes you say about the code?
Regards
I have added this code to megamenu-pro.php :
function ggstyle_menu_item_count( $output, $item, $depth, $args ) {
// Check if the item is a Category or Custom Taxonomy
if( $item->type == 'taxonomy' ) {
$object = get_term($item->object_id, $item->object);
// Check count, if more than 0 display count
if($object->count > 0)
$output .= "<span class='menu-item-count'>".$object->count."</span>";
}
return $output;
}
add_action( 'megamenu_walker_nav_menu_start_el', 'ggstyle_menu_item_count', 10, 4 );
It’s not working for me.
You would usually add the code to your themes functions.php file, but as I said previously, I’m afraid this level of custom development isn’t something we cover through support.
Regards,
Tom