In this tutorial, we are going to show you how can you display the total number of registered users on WordPress without the help of a plugin

You may have a website where you allow visitors to register on it. This can be a blog, e-commerce, or membership website. You may be asking: why would I want to show the total number of registered users on WordPress? This is a good question and one answer would be so people can see just how popular your website is. There are also other reasons such as wanting visitors who have never been there before to see what they’re missing out on by not registering themselves. Showing the total number of registered users publicly will help the audience to grow their confidence. It will also inspire them to register.

Considering the above in mind, you may want to add a section on your website which displays the total number of registered users.

We are going to show you how preciously you can do this. The entire process includes three 3 easy steps.

  1. Register a shortcode to return the total number of registered users on wordpress
  2. Wrap the shortcode with some HTML code
  3. Write some CSS to make the appearance better.

Register the shortcode

To accomplish this task, just copy and paste the following code to your theme’s functions.php file,

// Function to return user count
function cdxn_cx_user_count() {
    $usercount = count_users();
    $result = $usercount['total_users'];
    return $result;
}

// Creating a shortcode to display user count
add_shortcode('cx_user_count', 'cdxn_cx_user_count');

After that you added this code to your theme’s functions.php file, you can now use the shortcode [cx_user_count] in your WordPress posts, pages, or a sidebar widget to display the total user count.

But wait, this shortcode will just return the total number of registered users on the WordPress website. However, you may want to add some HTML, CSS and wrap this shortcode to give it a nicer look

For instance, here is a sample screenshot of the output and we wrapped this number with some HTML and CSS as described below.

Wrap the shortcode with some HTML code

Here is a sample HTML structure that you can use inside inside WordPress posts, pages, or a sidebar widget.

<!-- Wrapping [cx_user_count] with some HTML and CSS -->
<div class="cx-registered-user">
    <p>We have a total of <span>[cx_user_count]</span> users registered on our website till today. You are welcome to join with us also.</p>
</div>

Write some CSS to make the appearance better

You may want to copy and paste the below css inside your theme’s style.css file or inside theme customizer additional CSS section.

.cx-registered-user {
    background: #D1E4DD;
    padding: 30px;
    width: 100%;
    max-width: 1170px;
}

.cx-registered-user p {
    margin:0;
}

.cx-registered-user span {
    color: #ff4500;
    font-size: 32px;
    line-height: 1.1em;
}

That’s all and we hope you found this tutorial to be interesting and informative. In case of you love to explore some more tutorials, we invite you to check out these posts.

Thank you.