WordPress Recent Users

4919659112_b9f6b0df8f_o

Yesterday i came up in a situation to show the recently registered users in one of my ongoing projects. I have made this requirement by using below code.

This code can be placed in your function.php of theme.

function recently_registered_users() {
global $wpdb;
$recentusers = '<ul>';
$usernames = $wpdb->get_results("SELECT user_nicename, user_url, user_email FROM $wpdb->users ORDER BY ID DESC LIMIT 5");
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;
}


After that we need to use the below code for displaying it wherever you required. I have placed the code in my sidebar

<?php recently_registered_users(); ?>

If you wish to have a shortcode for this, it can be simply added by using the below code to the functions.php

add_shortcode('recentusers', 'recently_registered_users');

By adding this shortcode you can use the functionlaty where ever you need. Like in post, pages etc.

You may need to use the bellow shortcode for display the newly registered users in post, pages or widget.

[recentusers]

By adding this you can show your recently registered WordPress users in your sidebar or post or pages.

Hope this help some one…..!!!!!