Shortcode for Number of Users and Number of Posts

With this code, you can dynamically show, how many users and posts your blog has, by using the shortcodes

[user_count]

giving out this number: 1

and

[total_posts]

giving out this number: 25

Add this Code to your functions.php, f.ex. via Code Snippets.

function gooloo_total_posts() {
    $total = wp_count_posts()->publish;
    return $total;
}
add_shortcode('total_posts', 'gooloo_total_posts');

function gooloo_user_count() {
    $usercount = count_users();
    $result = $usercount['total_users'];
    return $result;
}
add_shortcode('user_count', 'gooloo_user_count');

Posted

in

by

Tags:

Comments

Leave a Reply

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