Showing registered users on WordPress using PHP
Ce contenu n’est pas encore disponible dans votre langue.
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.
Why Show Registered Users?
Section titled “Why Show Registered Users?”- Demonstrates site growth and credibility.
- Encourages new visitors to register.
- Useful for membership sites, forums, or communities.
Steps to Display Registered Users
Section titled “Steps to Display Registered Users”-
Log in to WordPress with an administrator account.
-
In the dashboard, go to Appearance → Theme Editor.
-
From the right‑hand column, select the file named functions.php.
-
Scroll to the bottom of the file and add the following code:
// Function to return user countfunction wpb_user_count() {$usercount = count_users();$result = $usercount['total_users'];return $result;}// Creating a shortcode to display user countadd_shortcode('user_count', 'wpb_user_count'); -
Click Update File to save changes.
⚙️ Using the Shortcode
Section titled “⚙️ Using the Shortcode”-
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.
Important Notes
Section titled “Important Notes”- 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.
Cette page vous a-t-elle aidé ?
Merci pour votre retour.