Skip to content

WordPress shortcode to display user registration date

    If your site offers the possibility for users to register, you might at some point want to be able to display users’ registration date. Here’s a super simple code snippet to create a WordPress shortcode that will display registration date of a specific user.

    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!

    Leave a Reply

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