Sometimes while creating plugins or themes you may required current user logged in ID in WordPress. There are various ways to fetch it, but today I am going to share with you two easiest approach to get logged in user’s ID.
Method 1: Using PHP code in WordPress
Use the code below to get current user id in WordPress.
$c_user_id = get_current_user_id();
echo 'User ID is: ' .$c_user_id;
The get_current_user_id function will give you the currently logged in user’s ID. But, if a user is not logged in, it will show 0.
Another common approach that uses some code is the get_currentuserinfo() function. It will give you the whole information of user that include username, email, first name, last name etc.
But, get_current_user_id() is more quick and fast technique to extract the user ID.
This function was included in WordPress 3.0 as part of the Multisite code, integrated with WordPress.
Method 2: Using a WordPress Plugin
In this method you will not only get current user id but you can check user id of other users in dashboard as well. We will use Reveal IDs WordPress plugin.
Simply install this WordPress plugin and then navigate to Users tab from WordPress dashboard. Here you will see all the user ids.
Please comments below if you find this article helpful or you need some help related to this topic.