WordPress shortcode to display user registration date

First, place the code below into your theme’s functions.php file and don’t forget to save.

function wpb_user_registration_date($atts, $content = null ) { 
	$userlogin = shortcode_atts( array(
		'user' => FALSE,
	), $atts );

	$uname = $userlogin['user'];     

	if ($uname!== FALSE) {             
		$user = get_user_by( 'login', $uname );  
	
		if ($user == false) { 
			$message ='Sorry no such user found.'; 
		} else { 
			$udata = get_userdata( $user-ID );
			$registered = $udata->user_registered;
			$message = 'Member since: ' . date( "d F Y", strtotime( $registered ) );
		}
	} else { 
		$message = 'Please provide a username.'; 
	} 

	return $message; 
} 

add_shortcode('membersince', 'wpb_user_registration_date');

Once done, you can now use the shortcode in your blog posts and pages. Let’s say you want to display since when “John” is a registered user of your blog:

[membersince user=john]

That’s it!

Credit: WpBeginner

Leave a Reply

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