Show recently registered users in WordPress

If you’re using WordPress, you already know that you can allow your visitor to register and become a part of your community. Although WordPress asks users to register and login with usernames, you can easily change that and allow anyone to use their email address for registration/login purposes instead. After you allow visitors to register, you may allow them different things on your website which an average visitor couldn’t get. For example, your registered users can feel more like home when commenting on your posts or you can give them exclusive material to download.

After some time of hard work, you may be having more than just a few registered users on your WordPress powered website. Hopefully, users will be registering daily and that’s just the right time to show a list of registered users somewhere on the site.

If you place a widget or designate a certain section of the homepage to display recently registered users, it might actually help you attract even more people. A simple list of few of the last registered users will show how active your site really is. To make everything even better, you can easily show a user’s avatar next to their username. So, if you have decided it’s time to show recently registered users, here’s how you can do that manually:

  1. Open functions.php file
  2. Copy and paste the following code:
  3. function recently_registered_users() {
    global $wpdb;
    $recentusers = '<ul class="recently-user">';
    $usernames = $wpdb->get_results("SELECT user_nicename, user_url, user_email FROM $wpdb->users ORDER BY ID DESC LIMIT 3");
    foreach ($usernames as $username) {
    if (!$username->user_url) :
    $recentusers .= '<li>' .get_avatar($username->user_email, 45) .$username->user_nicename."</a></li>";
    else :
    $recentusers .= '<li>' .get_avatar($username->user_email, 45).'<a href="'.$username->user_url.'">'.$username->user_nicename."</a></li>";
    endif;
    }
    
    $recentusers .= '</ul>';
    return $recentusers;
    }
  4. Save changes

Now you have prepared the turf for showcasing your recently registered users.  If you take a closer look at the code, you will find that the 4th line is a place to define a number of users which will be displayed. You are free to change the number to any number you want but we feel 3-5 is the best choice to go with.

But you’re still not done here. Function is added to your functions.php file and now you have to display it somewhere on your site.

Probably the easiest way to do that is to create a shortcode which you can put in your posts, pages or a widget:

  1. Open functions.php file
  2. Copy and paste the following code:
  3. add_shortcode('recent_registered', 'recently_registered_users');
    
  4. Save changes
  5. Use [recent_registered] shortcode anywhere you want to display the users

If you want to display new users in your templates, your header or footer for example, you can do that with the following code:

<?php recently_registered_users(); ?>

Or you can execute the shortcode you have already created:

<?php echo do_shortcode(‘[ert]’); ?>

That’s it. Now you have your 3 latest registered user displayed on your site. You can further style the code to make the list look better and to match your site’s design.

If you’re not into coding, you should check out how to display recently registered users with a plugin.

START YOUR OWN BLOG

This guide is an introduction to mastering the art of blogging. It provides easy to follow steps to start, maintain, and grow your blog.

Read the guide

Leave a Reply

Your email address will not be published. Required fields are marked *