For multi-user WordPress sites, you may want to showcase your users on different sections of your website. For example, you can display a list of authors with avatars, or add an author info box, etc. In this tutorial we will show you how to display recently registered users in WordPress. These users do not need to be authors. It can be used for a community site that allows for user registration.

First thing you need to do is copy and paste the following code in your theme’sfunctions.php file or in a site-specific plugin.

01 function wpb_recently_registered_users() {
02
03 global $wpdb;
04
05 $recentusers = '<ul class="recently-user">';
06
07 $usernames = $wpdb->get_results("SELECT user_nicename, user_url, user_email FROM $wpdb->users ORDER BY ID DESC LIMIT 5");
08
09 foreach ($usernames as $username) {
10
11 if (!$username->user_url) :
12
13 $recentusers .= '<li>' .get_avatar($username->user_email, 45) .$username->user_nicename."</a></li>";
14
15 else :
16
17 $recentusers .= '<li>' .get_avatar($username->user_email, 45).'<a href="'.$username->user_url.'">'.$username->user_nicename."</a></li>";
18
19 endif;
20 }
21 $recentusers .= '</ul>';
22
23 return $recentusers
24 }

Now you can display the users on your site by using the following template tag in your theme’s template file such as sidebar.php, footer.php etc:

1 <?php wpb_recently_registered_users(); ?>

If you want to display newly registered users on a specific page without creating a page template, then you can use a shortcode.

Simply add this code in your theme’s functions.php file or the site-specific plugin, just below the code you entered earlier.

1 add_shortcode('wpb_newusers', 'wpb_recently_registered_users');

This code will create a new shortcode for you to use in your posts, pages, or widgets. Use it like this:

[wpb_newusers]

We hope this article helped you display recently registered users in WordPress. For feedback and questions, please leave a comment.

Content Source