Your users are the superstars of your multi-user WordPress site. There are many ways you can highlight users and authors on your site. Previously we showed you how to add an author info box, and how to display recently registered users. In this article, we will show you how to display a random list of registered users in WordPress.
First thing you need to do is copy and paste the following code in your theme’s functions.php file or in a site-specific plugin.
function wpb_random_users() { global $wpdb; $randomusers = '<ul class="random-users">'; // Query database for users $usernames = $wpdb->get_results("SELECT user_nicename, user_url, user_email FROM $wpdb->users ORDER BY RAND() LIMIT 5"); // Display users in a list foreach ($usernames as $username) { if (!$username->user_url) : $randomusers .= '<li>' .get_avatar($username->user_email, 45) .$username->user_nicename."</li>"; else : $randomusers .= '<li>' .get_avatar($username->user_email, 45).'<a href="'.$username->user_url.'">'.$username->user_nicename."</a></li>"; endif; } $randomusers .= '</ul>'; return $randomusers; } add_shortcode('randomusers','wpb_random_users');
This code queries the WordPress users table in your database and selects a random row, then it outputs the results in a bulleted list with user’s avatar and name. If a user has provided the website URL in their profile, then it will link the user name to their website.
Next thing you need to do is display the list of registered users. To do this, all you need to do is add the following line of code in your theme file where you want the user list to be displayed (such as sidebar.php, footer.php etc).
<?php wpb_random_users(); ?>
You can also display a list of random users from your site using this shortcode in a post, page, or a widget.
[randomusers]
We hope this article helped you display a random list of registered users on your WordPress site. If you were looking to display a list of your staff members, then you should check out this tutorial on how to create a staff list in WordPress.
If you have any questions or feedback, then please leave us a comment below. Also don’t forget to follow us on Twitter and join us on Google+
WPBEGINNER STAFF help plz
i insert code, work fine.
i saw “SELECT user_nicename, user_url, user_email
How do make user_url – to go to profile ?
HI,
Pretty nice code! Thank You!
I am using Buddypress and bbPress, and I wonder how I can edit the code to use “user_nicename” with the url of profile and not with the website url?
Thanks
ah, Its working now!
I pasted to the code at the function.php in current theme.
is this correct, right?
when I pasted the code to function.php in root directory, It was not working..
This is called spam registrations. Check our guide on >a href=”https://www.wpbeginner.com/plugins/how-to-stop-spam-registrations-on-your-wordpress-membership-site/”>how to stop spam registrations in WordPress
WordPress has a built in user management system. By default when you install WordPress you add the first user which is the administrator. You can add more users to your site by clicking on Users menu item in the admin bar.
See: https://www.wpbeginner.com/glossary/user-role/
However, user registration is turned off by default. So if you would like users to be able to register on your site, then you would go to Settings -> General and scroll down to the registration section. There you can check the box next to ‘any one can register’ to open your site for user registration.
Thank you. I see that now. I do have it selected, and I’ve had a decent number of users added. I’m just not clear on how they are adding themselves.
Hi I want to know if there is a plugin that can let me display a list of people (name, last name, address etc) that are registered in my organization. Not on my site.
I have a access database with this info.
better said, can i host a access file in wordpress?
How do people register to become a registered user on my WordPress site? Many people register on my site but their emails do not appear to be genuine. Mostly the addresses look like gibberish and the username registered bears no resemblance to the email addresses. I have tried responding asking them to confirm their registration but there are no responses.
Please check out our article on how to stop spam registrations on your WordPress site.
I have the same question. Where are those people registering? I don’t see a button or link on my site to be able to do that. Sorry if its a stupid question!
Hello,
I know this is out of topic but how can I turn off a under construction page so the website is live to the public. Any suggestions? Looking forward a favorable answer. Thank you
Madeline
You can put a page back to draft. Edit the page and from the Publish Meta box, under the Status drop down menu, choose Draft. Your website will remain live but the page will become inaccessible. Once you are done with your changes you can publish the page.
Would this help google search?
Madeline
Probably not.
If you are to use this in your template files don’t you need to use an echo before the function call?
No.