Shortcode to show a user's display name
-
Hi,
I’m in need of some help!
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.
Please any help will be greatly appreciated!
Thanks,
Jon
- The topic ‘Shortcode to show a user's display name’ is closed to new replies.