Display total number of posts in WordPress by shortcode [ published-posts-count ]
Add to your theme’s functions.php
// Display the total number of published posts using the shortcode [ published-posts-count ] function customprefix_total_number_published_posts($atts) { return wp_count_posts('post')->publish; } add_shortcode('published-posts-count', 'customprefix_total_number_published_posts');
For pages use [ published-pages-count ]
:
// Display the total number of published pages using the shortcode [ published-pages-count ] function customprefix_total_number_published_pages($atts) { return wp_count_posts('page')->publish; } add_shortcode('published-pages-count', 'customprefix_total_number_published_pages');