In this post I want to explain that how to get current user information in wordpress, WordPress is a most popular CMS(Content Management System) in the world. In wordpress we can create/develop multiple types web applications like ecoomerce site, blog, portal etc. WordPress provide lots of plugins and themes we can use themes according to need and implement it in your site at this time every website have subscription option and registration page So we explain here how to get user information in wordpress.
WordPress provides lots of predefine functions and hooks which is most important for wordpress coding or customization of wordpress core functionality.
You can copy below code and paste in your file and get logged in user details using
wp_get_current_user() this function is a wordpress predefine function which returns login user details. It returns data in object format.
$current_user = wp_get_current_user();
echo 'Username: ' . $current_user->user_login . '<br />'; /// webprepration
echo 'User email: ' . $current_user->user_email . '<br />'; ///email@example.com
echo 'User first name: ' . $current_user->user_firstname . '<br />'; //web
echo 'User last name: ' . $current_user->user_lastname . '<br />'; //master
echo 'User display name: ' . $current_user->display_name . '<br />'; // web master
echo 'User ID: ' . $current_user->ID . '<br />'; //1