Adding category count | WordPress.org

[ad_1]

Try this one:

function custom_add_count_on_archive_title( $title ) {
 $term = get_queried_object();
 if( $term instanceof WP_Term && 'category' === $term->taxonomy ) {
  $title .= ' ('.$term->count.')';
 }
 return $title;
}
add_filter( 'get_the_archive_title', 'custom_add_count_on_archive_title', 10, 1 );

Add this in the functions.php of your child-theme or via Code Snippet-plugin.

It works, thank you. Maybe is it possible to style the number and the parethesis by css?

Replace

$title .= ' ('.$term->count.')';

with

$title .= ' <span>('.$term->count.')</span>';

and you should be able to style it via CSS, e.g.:

.page-title span { color: red; }

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer