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.
We Recommend
https://kinsta.com › wordpress-hosting
Fast and secure infrastructure, worldwide CDN, edge caching, 35 data centers, and enterprise-level features included in all plans. Free site migrations.
https://gravityforms.com › features
Create custom web forms to capture leads, collect payments, automate your workflows, and build your business online. All without ever leaving WordPress.
Leave a Comment