Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use WordPress core’s count_users() function, read its total_users value, and expose that value with a registered shortcode. Place the shortcode in a WordPress Shortcode block wherever the total should appear.

Register a shortcode that returns the total

Add this PHP through your site’s approved code-management and deployment process:

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

count_users() returns an array that includes total_users and avail_roles. The first is the overall role-based user total for the selected site. The shortcode callback must return the value; registering the shortcode makes [user_count] usable in content. WordPress documents the function at its count_users() reference, and shortcode registration and syntax are covered in the Shortcode API.

Insert the count in a post or page

  1. Open the post or page in the WordPress editor.
  2. Add a Shortcode block.
  3. Enter [user_count].
  4. Preview or publish the page and confirm that the number appears.

The shortcode returns only the number. Add wording around it in the editor, such as Registered members: [user_count], or style that surrounding text with your theme’s normal blocks or CSS. The illustrative walkthrough from WPBeginner uses this same pattern; its snippet-management step is optional, not a requirement of WordPress.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose the correct count scope

Current site

With no site ID supplied, count_users() counts users for the current site. That is the appropriate call for a single-site installation or for displaying the active site’s role-based total in a multisite context.

A specific site in multisite

Pass a site ID when you need the total for another site in the network. Make the scope explicit in the surrounding label so readers do not mistake one site’s total for a network total.

$user_count = count_users( 'time', $site_id );
return $user_count['total_users'];

The accepted site argument and returned values are defined in the count_users() documentation.

When an active-user count is actually wanted

get_user_count() is a different API. Its documented meaning is the number of active users in the installation or network, and its value may be cached on large sites and updated twice daily. Do not substitute it when the requirement is a site-level, role-based total. See the get_user_count() reference for that distinct scope.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Understand the performance strategies

count_users() supports time and memory strategies. The official reference describes the first as CPU-intensive and the second as memory-intensive:

Strategy Primary cost Documentation guidance
time More CPU work Described as handling around 107 users
memory More memory use Described as handling around 105 users

These figures are approximate guidance in the WordPress API documentation, not a benchmark or guarantee for your hosting environment. The default call shown above uses the function’s normal strategy. If you deliberately need the other strategy, pass it as the first argument:

$user_count = count_users( 'memory' );

The reference also assumes that capabilities metadata is not duplicated or orphaned and that role names are unique phrases. Unusual or damaged user metadata can therefore affect results or performance; investigate the data before treating an unexpected total as a display bug.

Common problems and fixes

The page shows [user_count] instead of a number

  • Confirm that the PHP defining add_shortcode( 'user_count', ... ) is active and loaded.
  • Check that the spelling and brackets in the editor exactly match [user_count].
  • Use a Shortcode block or another location where WordPress processes shortcodes; plain text that is not processed will remain literal.

The number is not the number you expected

  • Verify whether you need the current site, another multisite site ID, or an installation/network active-user count.
  • Ensure you are reading $user_count['total_users'], not the avail_roles breakdown.
  • Check for duplicated or orphaned capabilities metadata, which the core reference excludes from its normal assumptions.

The site becomes slow or runs out of memory

Review the strategy choice and hosting limits. time trades memory for CPU, while memory trades CPU for memory. Test changes on a staging copy and deploy through your normal review process rather than editing production code blindly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Label the result accurately

A bare number can be misleading. Put the scope in the visible text—for example, “Registered users on this site: [user_count]” for a site total. If you use a network-wide active-user value instead, label it as such and account for the cache behavior documented for get_user_count().

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.