WordPress show total number of published posts, cats,comments and views in static pages

I’m trying to show my site stats in a static page, following snippet works on page templates. I would like to know how can I turn it to a shortcode so that I can paste it into any static page e.g. in “about us” page?

<?php
$total_posts = wp_count_posts( ‘post’ );
$total_posts = $total_posts->publish;
$total_cats = wp_count_terms(‘category’);
$total_comments = get_comment_count();
$total_comments = $total_comments[‘approved’];
echo ‘In our site there are ‘; echo $total_cats; echo ‘ cats; ‘; echo $total_posts; echo ‘ Posts and ‘; echo $total_comments; echo’ comments.’;
?>

Read more here:: WordPress show total number of published posts, cats,comments and views in static pages

Leave a Reply

Your email address will not be published. Required fields are marked *