How to show WordPress Username on your website

  WordPress

Here’s a function I found where it creates a shortcode where you can place anywhere on your website through the editor, widgets, etc. I use DIVI, so it works with it also.

The shortcode after you put function in your themes functions.php is [show_loggedin_as]

Put the following in your child themes functions.php


function show_loggedin_function( $atts ) {

global $current_user, $user_login;
get_currentuserinfo();
add_filter(‘widget_text’, ‘do_shortcode’);
if ($user_login)
return ‘Welcome ‘ . $current_user->display_name . ‘!’;
else
return ‘Login’;

}
add_shortcode( ‘show_loggedin_as’, ‘show_loggedin_function’ );

Reference: https://webhostinghero.org/show-username-in-wordpress-sidebar/

LEAVE A COMMENT