Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Display total number of posts using a shortcode. Source: https://codex.wordpress.org/Function_Reference/wp_count_posts
<?php
// 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');
<?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');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.