Shortcode to show a user's display name
-
Hi,
This question was asked 3 years ago at this topic: Press hereSo I just paste the same question in quotes. I was trying to user get_userdata(); instead of get_avatar( $id ); but it didn’t work. Any ideas how to solve that issue?
“I’m trying to create a simple shortcode that will show a user’s display name based on the user ID you insert (or default to the currently logged in user if no ID is provided). Below is a similar shortcode I’ve created to do this for a user’s avatar:
<?php function avatar_shortcode( $atts ) { global $current_user; $user_id = ( is_user_logged_in() ? $current_user->ID : NULL ); extract( shortcode_atts( array( 'id' => $user_id, ), $atts ) ); return get_avatar( $id ); } add_shortcode('avatar', 'avatar_shortcode'); ?>
[avatar] displays the currently logged in user’s avatar and [avatar id=”1″] display’s the avatar for the user with an ID of 1 and so on. This is exactly what I am looking for to show a user’s display name. Something where [display-name] will show the currently logged in user’s display name and [display-name id=”1″] will show the display name for the user with an ID of 1 and so on.”
Thanks everyone in advance.
- The topic ‘Shortcode to show a user's display name’ is closed to new replies.