Use the below example code to display logged-in username IF logged-in
1 2 3 4 | <?php global $current_user; wp_get_current_user(); ?> <?php if ( is_user_logged_in() ) { echo 'Username: ' . $current_user->user_login . "\n"; echo 'User display name: ' . $current_user->display_name . "\n"; } else { wp_loginout(); } ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.