WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to get the ID of the currently logged in user. I've found the function: get_current_user_id which seems to be working, however I'm not sure what 'current' means in this context.

Meaning if the user views the profile of another user, then will the current user change to become the other user?

In short I'm looking for a reliable way to always get only the id of the logged in user.

share|improve this question
up vote 2 down vote accepted

get_current_user_id() effectively does what @Giri had described in the first snippet. The internal Wordpress function-call chain eventually calls get_currentuserinfo() which already checks if there is a WP_User object, meaning a user is logged in.

Thus, from what I can see in the linked code, get_current_user_id() always returns the ID of the user that is logged in or zero 0.

In the current default theme twentytwelve they are using get_the_author_meta() to retrieve information about the user, for whom the current author page is displayed. So the difference in WP terminology seems to be "user" for th current, logged in user and "author" for some user, identified by an ID. See: twentytwelve/author.php.

share|improve this answer
Hope you are right. – Click Upvote Dec 27 '12 at 19:44
@ClickUpvote see the updated last link on author.php – feeela Dec 27 '12 at 19:48
if( is_user_logged_in() ) {   
 global $current_user;
    $userid = $current_user->ID;


Use it like this

if( is_user_logged_in() ) {   
    $userid = get_current_user_id();
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.