Do you want to show the total number of posts on your WordPress site? Showing total number of articles may help showcase the consistency of your blog and encourages users to look for more content. In this article, we will show you how to easily display total number of posts in WordPress.
Method 1: Show Total Number of Posts in WordPress Using a Plugin
This method is easier and recommended for all users.
First thing you need to do is install and activate the Simple Blog Stats plugin. For more details, see our step by step guide on how to install a WordPress plugin.
Upon activation you need to visit Settings » Simple Blog Stats to configure plugin settings.
Simple Blog Stats plugin shows you useful WordPress stats like total number of comments, users, pages and posts. You can easily display these stats using shortcodes anywhere on your WordPress site.
Simply copy the [sbs_posts]
shortcode and add it to any WordPress post, page, or shortcode enabled sidebar widget.
It will show the total number of published posts on your WordPress site.
You can also use [sbs_blog_stats] which will show all blog stats including the total number of posts.
Method 2. Manually Display Total Number of Posts in WordPress
This method requires you to add code to your WordPress site. If you haven’t done this before, then take a look at our guide on how to copy and paste code in WordPress.
First you need to add this code to your theme’s functions.php file or a site-specific plugin.
function wpb_total_posts() { $total = wp_count_posts()->publish; echo 'Total Posts: ' . $total; }
This code simply output the total number of posts whenever the template tag wpb_total_posts
is called.
Next, you need to add <?php wpb_total_posts(); ?>
in your theme files where you want to display total number of posts.
If you don’t want to use the template tag, then you can create and use a shortcode that does exactly the same thing.
Copy and paste the following code to your theme’s functions.php file or a site-specific plugin to create a shortcode:
function wpb_total_posts() { $total = wp_count_posts()->publish; return $total; } add_shortcode('total_posts','wpb_total_posts');
Now you can use the shortcode [total_posts]
to display total number of posts in any posts, pages, or sidebar widgets.
We hope this article helped you learn how to show total number of posts in WordPress. You may also want to see our mega list of most wanted WordPress tips, tricks, and hacks.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Dele says
Works well for me. Thanks for this
WPBeginner Support says
Glad you found our article helpful!
Admin
Youri says
Does not work for me
Is it because of code updates? Would love to see an updated version if so
WPBeginner Support says
We’ll be sure to take a look at our code, for the time being, you may want to look into the plugin for an alternative
Admin
sam88 says
works for me thank you!
WPBeginner Support says
You’re welcome, glad our guide could help
Admin
Rana says
How exclude a specific category form counting?
WPBeginner Support says
For the plugin, you would want to reach out to the plugin’s support for if that is an option in the current version.
Admin
Amanda says
How do I show the number of posts for a particular tag? Thanks in advance
WPBeginner Support says
The tag cloud widget should do what you’re wanting by default
Admin
Itisme64 says
Hi Nice and works great with the shortcode. Tried plugin and stopped the website.
How do i get separate like 21.500 posts ? now it say 21500
cheers
WPBeginner Support says
Using the shortcode method in your functions.php or your site-specific plugin you would replace:
return $total;
With:
return number_format_i18n($total);
to add the comma
Admin
itisme64 says
Thanks for quick reply and works fine
jay says
Thanks for the extremely useful article (for us non-programmers). What if I have 6 different categories of posts (related to, say, jobs, offices for rent, supplies, etc.), and I want to get a separate count for each category?
WPBeginner Support says
Hi Jay,
If you just want to show how many posts are there in each category then you can use the Categories widget and add it to your sidebar. In widget settings you will see an option to display the number of posts next to each category.
Admin