Are you a WordPress developer or just started with WordPress, If your answer is yes, then keep bookmark this blog because you will always get the updates about WordPress and also you will get the tips & tricks of WordPress which help you a lot while you developing your next application using WordPress.
This si very short and quick tutorial, but it very useful tips of WordPress. In today tutorial, I will explain How to get the user details of current logged in user in WordPress.
copy th below code and use in your php page or templates where you need. This will get the all the details of current logged in user from your WordPress site. Use the
wp_get_current_user() this function will return the
WP_User object. wp_get_current_user() function is located at wp-includes/pluggable.php file.
$current_user = wp_get_current_user();
* @example Safe usage: $current_user = wp_get_current_user();
* if ( !($current_user instanceof WP_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 />';
The output will look like:
If you have just started with WordPress, then check out:
By using the above function you can personalise your site experience for your users. Hope this tutorial help you, Do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to learn cool WordPress tutorials.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: useful tips of WordPress, wordpress tutorial, wordpress tutorial for beginner, wordpress tutorial for beginners, wordpress tutorials, wordpress tutorials for beginners, Wordpress useful tips