Archived topic
How to add number of posts in category title
3 replies · Started by Anastasios on August 18, 2018
Hi,
there is a way to add the number of category posts in the category title?
For example: The category "Summer vacations" to be "12 Posts about summer vacations" where number changes automatically.
Also in Tags archive.
Thank you in advance.
Hi there,
You may be able to do something like this: https://wordpress.stackexchange.com/a/20977
For example:
add_action( 'generate_after_archive_description', function() {
if ( is_category() ) {
$category = get_category();
$count = $category->category_count;
if ( $count ) {
echo 'This category has ' . $count . ' posts.';
}
}
} );
Hi Tom.
I created a new header element for category archives. Am i able to add this action inside this header or have i to create and add it in a new hook? Will it work if i paste this code in a new hook element and select the display options for inside header?
Thanx.
Hi there,
Elements > Header can't execute PHP. And the code Tom has provided is already applying the Hook, its best added to a Child Function file or using Code snippets plugin. See here: