WordPress tutorials: User ID from username

Wpsnipp – In your theme code or plugin code, if you know the user name or user login of the WordPress user, you can easily obtain all the user information stored in WordPress database using the below function.Adding this PHP code to your wordpress theme will return the user ID from the username.By using get_userdatabylogin



$user = get_userdatabylogin('admin');
if($user) echo $user->ID;

Leave a comment