Get current logged in user ID in WordPress

Sharing is caring!

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.

get-current-user-id-in-wordpress

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.

Sharing is caring!

Summary
How to Get current logged in user ID in WordPress
Article Name
How to Get current logged in user ID in WordPress
Description
You can get current user id in two ways: 1. Using PHP code 2. Using a WordPress Plugin Firstly I will show you how to fetch current user id in WordPress...
Author
Publisher Name
WebSoftTutorials
Publisher Logo
Rishab Kapoor on FacebookRishab Kapoor on LinkedinRishab Kapoor on TwitterRishab Kapoor on Youtube
Rishab Kapoor
A Blog writer, a Web developer and a passionate teacher. Teaching on YouTube from last 7 years. Like to write articles about Web designing, Web development, Digital Marketing, and Online money making techniques. If you have any question about Web technologies and your career then you can contact me via above my social media profiles.