xxxxxxxxxx
$current_user = wp_get_current_user();
$user_id = $current_user->ID;
xxxxxxxxxx
<?php $user_info = get_userdata(1);
echo $user_info->last_name . ", " . $user_info->first_name . "\n";
?>
xxxxxxxxxx
$current_user_id = get_current_user_id();
$current_user = wp_get_current_user();
xxxxxxxxxx
$username = 'your user name';
$user = get_user_by('login', $username);
xxxxxxxxxx
do not user javascript body class method sometimes it will give issue due to cache
<?php
function detect_login() {
$isLoggedIn = is_user_logged_in();
wp_register_script( 'detect_login', '' );
wp_enqueue_script( 'detect_login');
wp_add_inline_script( 'detect_login', "var isLoggedIn = $isLoggedIn" );
}
add_action( 'wp_enqueue_scripts', 'detect_login' );
to get the value :
window.isLoggedIn