Hello guys, if you have wondered how to get the current logged in user object and the current logged in user ID, then read this simple and short article that provides the code for doing this. There are 2 simple functions and cases for doing this.
1. First situation is to get the current logged in user object. The object can be useful if you want to get the user email, or the username itself of that user. See below the code for that:
<?php
//get the current user object
$current_user
= wp_get_current_user();
//do something with it
$email = $current_user->user_email;
echo $email;
?>
2. Second, get only the current logged in user ID:
<?php
$current_user_id
= get_current_user_id();
echo $current_user_id;
?>
The article is simple, but it helps a lot of people