Created
August 21, 2015 15:58
-
-
Save generatepress/050648ac7d2d566865ac to your computer and use it in GitHub Desktop.
Add category post count to the menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_filter('the_title', 'generate_category_post_count_title', 10, 2); | |
function generate_category_post_count_title($title, $post_ID) | |
{ | |
if( 'nav_menu_item' == get_post_type($post_ID) ) | |
{ | |
if( 'taxonomy' == get_post_meta($post_ID, '_menu_item_type', true) && 'category' == get_post_meta($post_ID, '_menu_item_object', true) ) | |
{ | |
$category = get_category( get_post_meta($post_ID, '_menu_item_object_id', true) ); | |
$title .= sprintf(' (%d)', $category->count); | |
} | |
} | |
return $title; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome Thanks :) works with WP 4.9.1