Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Show Total Number of Posts in WordPress

Editorial Note: We earn a commission from partner links on WPBeginner. Commissions do not affect our editors' opinions or evaluations. Learn more about Editorial Process.

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.

Show total number of posts in WordPress

Why Display the Total Number of Posts in WordPress?

If you’ve published a lot of articles, showing the total number of posts in WordPress is a great way to display social proof.

It shows website visitors that you’re consistent with publishing new content and that you have a lot of experience on the topic that you write about. This can help boost trust with your visitors and encourage them to become loyal readers and subscribers.

Showing the total number of posts can also encourage visitors to stay on your site longer. If they know that you have tons of other articles they can read, they’ll be more likely to stick around and check them out.

With that said, we’ll show you two different methods for displaying the total number of posts in WordPress. You can use the quick links below to jump right to the method you want to use.

Method 1: Show Total Number of Posts in WordPress Using a Plugin

This method is easier and recommended for all users.

The 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.

Blog stats shortcodes

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.

number of posts

You can also use [sbs_blog_stats] which will show all blog stats including the total number of posts.

Blog stats

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 code snippets plugin.

function wpb_total_posts() { 
$total = wp_count_posts()->publish;
echo 'Total Posts: ' . $total;
} 

This code will simply output the total number of posts whenever the template tag wpb_total_posts is called.

The easiest way to add this code in WordPress is by using a code snippets plugin like WPCode. It lets you safely add code without editing your theme’s functions.php file, so you don’t need to worry about breaking your site.

To get started, you need to install and activate the free WPCode plugin. If you need help, follow our tutorial on how to install a WordPress plugin.

Once the plugin is activated, go to Code Snippets » + Add Snippet from the WordPress dashboard. On the Add Snippet page, find the ‘Add Your Custom Code (New Snippet)’ option and click the ‘Use snippet’ button underneath it.

Add a new custom code snippet in WPCode

Next, add a title for your snippet and paste the code from above into the ‘Code Preview’ box. Don’t forget to also choose ‘PHP Snippet’ as the code type from the dropdown list on the right.

Paste code into the WPCode plugin and select the code type

After that, simply toggle the switch from ‘Inactive’ to ‘Active’ and click the ‘Save Snippet’ button.

Activate and save your custom code snippet

Once that’s done, 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 code snippets plugin to create a shortcode:

function wpb_total_posts() { 
$total = wp_count_posts()->publish;
return $total; 
} 
add_shortcode('total_posts','wpb_total_posts');

You can follow the same steps as above to easily add this code using the WPCode plugin.

Paste code in the WPCode plugin to create shortcode

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 or our picks of the best related posts plugins for WordPress.

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.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

16 CommentsLeave a Reply

  1. Syed Balkhi says

    Hey WPBeginner readers,
    Did you know you can win exciting prizes by commenting on WPBeginner?
    Every month, our top blog commenters will win HUGE rewards, including premium WordPress plugin licenses and cash prizes.
    You can get more details about the contest from here.
    Start sharing your thoughts below to stand a chance to win!

  2. 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

    • 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

  3. 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

  4. 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

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WPBeginner Assistant
How can I help you?

By chatting, you consent to this chat being stored according to our privacy policy and your email will be added to receive weekly WordPress tutorials from WPBeginner.