Post Count in Archive Titles
Adds the number of posts to category, tag, author and date archive headings, for example "Recipes (42)".
Opens WPIDE on
Code
add_filter( 'get_the_archive_title', function ( $title ) {
global $wp_query;
if ( ! is_archive() || is_post_type_archive() || ! $wp_query instanceof WP_Query ) {
return $title;
}
return $title . ' <span class="wpide-archive-count">(' . esc_html( number_format_i18n( (int) $wp_query->found_posts ) ) . ')</span>';
}, 20 );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.