Skip to content

Instantly share code, notes, and snippets.

@jpmarchand
Last active May 25, 2017 20:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpmarchand/e510527894bcc2f83d8b to your computer and use it in GitHub Desktop.
Save jpmarchand/e510527894bcc2f83d8b to your computer and use it in GitHub Desktop.
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