WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

WPMU Functions/get current user id

Description

Returns the ID of the current viewer if they are logged in. Returns 0 if the viewer is not logged in.

Parameters

None.

Return Values

(integer) 
User ID of the current viewer, or 0 if the current viewer is not logged in.

Usage

<?php get_current_user_id( ); ?>

Examples

<?php
$user_id 
get_current_user_id();
if (
$user_id == 0) {
    echo 
'You are currently not logged in.';
} else {
    echo 
'You are logged in as user '.$user_id;
}
?>