In wordpress current user means, Who written current post or article.In this article we are going show you, how to get current user information in wordpress. Following methods are useful when user are logged in to wordpress CMS.
You can print the user information using following information. Retrieves the information pertaining to the currently logged in user, and places it in the global variable $current_user.
how to get current user information in wordpress
You can put following code in your theme folder.
<?php global $current_user; get_currentuserinfo(); echo 'Username: ' . $current_user->user_login . "\n"; echo 'User email: ' . $current_user->user_email . "\n"; echo 'User first name: ' . $current_user->user_firstname . "\n"; echo 'User last name: ' . $current_user->user_lastname . "\n"; echo 'User display name: ' . $current_user->display_name . "\n"; echo 'User ID: ' . $current_user->ID . "\n"; ?>
Or you can use following code for showing the current user information
<?php wp_get_current_user(); ?> <?php $user_info = get_userdata(1); echo 'Username: ' . $user_info->user_login . "\n"; echo 'User roles: ' . implode(', ', $user_info->roles) . "\n"; echo 'User ID: ' . $user_info->ID . "\n"; ?>
For more detailed information you can visit following link:
http://codex.wordpress.org/Function_Reference/get_userdata