Tutorials WordPress

Display Total Number of WordPress Pages

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 pages on your entire site? Use the following code to get the total number of pages, and then display it in your theme. This only gets published pages, not the pages with “Draft” status.

<?php // Get total number of pages published
	$count_pages = wp_count_posts('page');
	$total_pages = $count_pages->publish;
	echo $total_pages . ' pages. ';
?>

The $total_pages variable will just return the number. You can change the word “pages” to say whatever you want.

I’d love to see how you use this. Please share 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