? The Snippet:
$current_user = wp_get_current_user();
echo 'Username: ' . $current_user->user_login . '<br />';
echo 'User email: ' . $current_user->user_email . '<br />';
echo 'User first name: ' . $current_user->user_firstname . '<br />';
echo 'User last name: ' . $current_user->user_lastname . '<br />';
echo 'User display name: ' . $current_user->display_name . '<br />';
echo 'User ID: ' . $current_user->ID . '<br />';
ℹ️ About the Snippet
In WordPress User Profile settings, a user can save his/her information like first name, last name, email etc. If we want to show/display WordPress user information currently logged in, then this snippet can be used. Remember, to grab the current user’s information, a user must have to be logged in. For safe usage, you can “Check if WordPress User is Logged in”.
✅ How to use the Snippet
First, you’ll have to identify the place where you want to get the user’s information and show. Once decided, then you can make a variable of the current user’s information like this:
$current_user = wp_get_current_user();
After that, with the help of that variable, you can print the required information. For example, if you want to show user’s email only, it’ll be like this:
$current_user = wp_get_current_user();
echo 'User email: ' . $current_user->user_email;