Display Total Number of WordPress Users

Do you want to display the total number of WordPress users on your entire site? Use the following code to get the total number of users, and then display it in your theme. This returns ALL users, regardless of User Level.

<?php // Get total number of users
	$total_users = count_users();
	echo $total_users['total_users'] . ' users.';
?>

The $total_users variable will just return the number. You can change the word “users” to say whatever you want (registered users, people, etc.).

I’d love to see how you use this. Please share in the comments.

Reference count_users() in the WordPress Codex.

10 Commentson "Display Total Number of WordPress Users"

    1. (Author) /

      Sure thing, Harold. I hope you found it useful.

  1. /

    Hey Dave,
    You can also turn this into a shortcode to display it in a post or a widget quite easily.

    The code below will simply output the number of users (without the word “users” after it) when the shortcode [NUMBERUSER] is used.

    add_shortcode(‘NUMBERUSER’,’show_number_users’);
    function show_number_users(){
    $total_users = count_users();
    echo $total_users[‘total_users’];
    }

    Hope this helps someone out!

    All the best,

    Manny.

    → Reply
    1. (Author) /

      Great idea, Manny. I can see how a shortcode might be helpful here. Thanks for sharing.

  2. /

    I’m sorry, but I’m not real WordPress literate – could you tell me exactly WHERE I should put the code to display users? Thanks!

    → Reply
    1. (Author) /

      Michael,

      You have a few options as to where you place the code.

      If you use the original code I posted, you would need to place that in one of your theme’s template files. For example, to place it on all single posts, you’d put it in single.php. To place it in the sidebar somewhere, you would put it in sidebar.php. These files are found inside of your current theme folder.

      If you wanted to output the number of users inside the actual content of a post or page, you should look at Manny’s advice above. You would place Manny’s code in your theme’s functions.php file, and then use “[NUMBERUSER]” inside of an actual post or page.

      Does that make sense?

    2. /

      Yes, that helps. I would have to put it in my theme, as I am not experienced with PHP coding, and wouldn’t want to screw up my site! LOL Thanks very much.

    3. (Author) /

      Haha, understood. It is pretty basic PHP code, but you always want to be careful when editing a functions.php file. Best of luck.

  3. /

    I know this is an older thread, but I just found it and tried it – I could not get the code to work as described on WP 4.5.3

    → Reply
    1. (Author) /

      Trevor — If you post a code sample, I’ll take a look and see if I can help.

      You can use something like codepen or jsfiddle to post your code.

What Are Your Thoughts?

All fields are required. Your email will not be published.

You can use standard <code> and <pre> tags to post code examples, or a service like codepen.io.