wppostcount
How to Show Total Number of Posts in WordPress
August 17th, 2018 in Wordpress |

Do you want to show the total number of posts on your WordPress site? Showing the 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 the 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.

The first thing you need to do is install and activate the Simple Blog Stats 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 the total number of comments, users, pages, and posts. You can easily display these stats using shortcodes anywhere on your WordPress site.

sbsshortcodes

Simply copy the shortcode[sbs_posts] 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.

numberofposts

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

blogstatsall

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 the code in WordPress.

First, you need to add this code to your theme’s functions.php file or a site-specific plugin.

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

This code simply outputs the total number of posts whenever the template tag iswpb_total_posts called.

Next, you need to add in<?php wpb_total_posts(); ?> your theme files where you want to display the 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:

1
2
3
4
5
function wpb_total_posts() {
$total = wp_count_posts()->publish;
return $total;
}
add_shortcode('total_posts','wpb_total_posts');

Now you can use the shortcode to[total_posts] display the total number of posts in any posts, pages, or sidebar widgets.

We hope this article helped you learn how to show the total number of posts in WordPress.