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