get_current_user_id
The function get_current_user_id() in WordPress is a core function that retrieves the ID of the currently logged-in user. If no user is logged in, it returns 0.
Table of Contents
The function get_current_user_id()
in WordPress is a core function that retrieves the ID of the currently logged-in user. If no user is logged in, it returns 0
.
$current_user_id = get_current_user_id();
if ($current_user_id) {
echo "Logged-in user ID: " . $current_user_id;
} else {
echo "No user is logged in.";
}
Function Definition
- Location: Defined in
wp-includes/pluggable.php
. - Returns:
int
– The user ID if logged in, otherwise0
.
This function is typically used within hooks or templates where you want to identify the user performing the action or viewing the page.