Show User Count Using Count_Users

The code snippets in this tutorial enable you to display a count of all users.

  • You can choose from using a custom function with WordPress or theme specific hook
  • Or a shortcode for use within the content area of a page or post and in a text widget.
Any PHP code on this page should be copied from the view raw link in the Gist and pasted at the end of your functions file using a code editor.

Show User Count Using Shortcode

Paste this PHP code into your functions file and use the shortcode to display a count of all users wherever you use the shortcode.

You can also use this shortcode in any text widget as long as your theme supports the use of shortcodes in widgets.

Add Theme Support for Shortcodes in Widgets

Simply paste this line of PHP code in your functions file

You can also display a list of members using a custom function with WordPress or theme specific hook.

Show User Count Using WordPress Hook

This code produces this result:

wp user count

Show User Count Using Theme Specific Hook

This code produces this result:

Show Member Count

Uses the genesis_entry_header hook which you can easily change to your own theme specific hook.

Other Options

If you need more flexibility and want to list different user roles and the count_total for each, use WP_User_Query which is a class that enables you to query your ‘wp_users’ and ‘wp_usermeta’ database tables.

WP_User_Query includes a huge range of parameters like the count_total parameter which is relevant in this case.

Question Source – SP Forums

I am working on a learning site and would like to display how many member have signed up to the site. This is to be incorporated within a page and I don’t really want to install a plugin just for this one function.

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.