As a seasoned WordPress developer with years of experience building community-driven sites, I know showcasing your users fosters engagement. We've previously covered author info boxes and recent registrations—now, here's how to randomly display registered users on your site.

Add this reliable code to your theme's functions.php file or a site-specific plugin:
function wpb_random_users() {
global $wpdb;
$randomusers = '<ul>';
// Query database for random 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 proven function queries your WordPress users table, selects 5 random entries, and outputs a bulleted list with avatars and names. If a user provides a website URL in their profile, it links to that site.
To display the list anywhere in your theme (like sidebar.php or footer.php), add:
<?php echo do_shortcode('[randomusers]'); ?>Alternatively, use the shortcode [randomusers] directly in posts, pages, or widgets for quick integration.
This approach has helped countless sites highlight their communities effectively. For staff showcases, see our guide on creating a staff list in WordPress.
Questions? Drop a comment below. Follow us on Twitter for more tips (Google+ updates discontinued).