In WordPress we can get the logged in user information such as firstname, lastname, displayname and ID in the following way.
<?php
$current_logged_user = wp_get_current_user();
?>
Now you have all the user information in the $current_logged_user variable. You can access the information in the following way.
<?php
echo 'Username: ' . $current_logged_user->user_login . '<br />';
echo 'User email: ' . $current_logged_user->user_email . '<br />';
echo 'User first name: ' . $current_logged_user->user_firstname . '<br />';
echo 'User last name: ' . $current_logged_user->user_lastname . '<br />';
echo 'User display name: ' . $current_logged_user->display_name . '<br />';
echo 'User ID: ' . $current_logged_user->ID . '<br />';
?>
No comments:
Post a Comment