Check user is admin in wordpress easily and without plugin.

Check User Is Admin

We will check user is admin using user roles in wordpress.

Copy “Admin Checker Function” code and paste it in functions.php file in your wordpress theme.

Admin Checker Function

function WPTime_admin_checker(){
if( is_user_logged_in() ){ // check if user is logged or not logged
$get_user_id = get_current_user_id(); // get user ID
$get_user_data = get_userdata($get_user_id); // get user data
$get_roles = $get_user_data->roles; // get user role
return in_array('administrator', $get_roles); // check if role is admin
}
}

Usage

After copy and paste “Admin Checker Function” in functions.php file, now use this code to check user is admin or not admin:

<?php
if( WPTime_admin_checker() ){
// he is admin!
}else{
// he is not admin!
} ?>