Skip to content

Showing registered users on WordPress using PHP

WordPress stores all registered users in its database. You can display the total number of registered users on your site using a simple PHP function. On ruachost.com, this is often used to highlight site popularity or community size.

  • Demonstrates site growth and credibility.
  • Encourages new visitors to register.
  • Useful for membership sites, forums, or communities.
  1. Log in to WordPress with an administrator account.

  2. In the dashboard, go to Appearance → Theme Editor.

  3. From the right‑hand column, select the file named functions.php.

  4. Scroll to the bottom of the file and add the following code:

    // Function to return user count
    function wpb_user_count() {
    $usercount = count_users();
    $result = $usercount['total_users'];
    return $result;
    }
    // Creating a shortcode to display user count
    add_shortcode('user_count', 'wpb_user_count');
  5. Click Update File to save changes.

  • To display the total number of registered users anywhere on your site, type:

    [user_count]

✅ WordPress will automatically replace [user_count] with the total number of registered users.

  • Always back up your site before editing theme files.
  • Consider using a child theme to preserve changes during updates.
  • This shortcode works in posts, pages, and widgets.