WordPress shortcode to display user registration date

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

The post WordPress shortcode to display user registration date appeared first on WPRecipes.

What’s My SEO Score?

Enter the URL of any landing page or blog article and see how optimized it is for one keyword or phrase.

Wordpress Expert
Rating

Leave a Reply