Tutorials WordPress

Display Total Number of WordPress Posts

Updated

Written by

Dave Warfel

Reading Time

1 minute

If you buy something from one of our links, we may earn a commission.

Do you want to display the total number of WordPress posts on your entire site? Use the following code to get the total number of published posts, and then display it in your theme.

<?php // Get total number of posts published
	$count_posts = wp_count_posts();
	$total_posts = $count_posts->publish;
	echo $total_posts . ' posts. ';
?>

The $total_posts variable will just return the number. You can change the word “posts” to say whatever you want (articles, entries, etc.).

Get creative with how you use this, and share it in the comments.

Reference wp_count_posts() in the WordPress Codex.

Dave Warfel

LinkedIn  •  X (Twitter)Dave has been working with WordPress since 2011. He's built 100s of client sites and almost a dozen of his own. He's tested almost every plugin you can think of, hosted with at least 10 different companies, and gone down every SEO rabbit hole you can imagine. When's he's not tinkering with new software, you'll find him in the mountains of Colorado, trail running, summiting peaks, and rippin' downhills on his mountain bike. 🏔️🏃🚴🤸

Leave a Comment