Tutorials WordPress

Display Total Number of WordPress Users

Updated

Written by

Dave Warfel

Reading Time

1 minute

If you buy something from one of our links, we may earn a commission.

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.

Dave Warfel

LinkedIn  •  X (Twitter)
Dave has been working with WordPress since 2011. He's built 100s of client sites and almost a dozen of his own. He's tested almost every plugin you can think of, hosted with at least 10 different companies, and gone down every SEO rabbit hole you can imagine. When's he's not tinkering with new software, you'll find him in the mountains of Colorado, trail running, summiting peaks, and rippin' downhills on his mountain bike. 🏔️🏃🚴🤸

10 responses to “Display Total Number of WordPress Users”

  1. Harold Avatar

    thanks for posting this..

    1. Dave Warfel Avatar

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

  2. Manny Avatar

    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.

    1. Dave Warfel Avatar

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

  3. Michael Avatar

    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!

    1. Dave Warfel Avatar

      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. Michael Avatar
      Michael

      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. Dave Warfel Avatar

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

  4. Trevor Townsend Avatar
    Trevor Townsend

    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

    1. Dave Warfel Avatar

      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.

Leave a Comment