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.
Latest posts by WordPress Expert (see all)
- How to Embed Instagram Feed in WordPress (5 Easy Steps) - September 26, 2023
- MemberPress vs WishList Member: Which is The Best Membership Plugin? - September 18, 2023
- 7 Best Divi Builder Alternatives for Your Website (Compared) - September 14, 2023