Skip to content

Instantly share code, notes, and snippets.

@thecodepoetry
Created December 25, 2020 11:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thecodepoetry/40ab38d3e242c3c34e320ac1c5c37916 to your computer and use it in GitHub Desktop.
Save thecodepoetry/40ab38d3e242c3c34e320ac1c5c37916 to your computer and use it in GitHub Desktop.
Display logged user name shortcode
function dt_display_username_func( $atts ){
if(is_user_logged_in()) {
global $current_user;
return 'Welcome: ' . $current_user->display_name;
}
else return;
}
add_shortcode( 'username', 'dt_display_username_func' );
@thecodepoetry
Copy link
Author

Please try this code in your child theme fucntions.php
Then insert shortcode [username] to display the user name.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment