How to check if the current user is Administrator in WordPress

Last Updated:

Here's how to check if the currently logged in user is an administrator in WordPress. This is useful if you want your content to be displayed only to administrators or to non-administrators.

How to check whether a user is administrator or not

To check if the currently logged in user is an administrator, use the current_user_can function.

To check if a user is an administrator, you can specify the capability as an argument of current_user_can function (e.g. manage_options).

For Administrators

if ( current_user_can( 'manage_options' ) ) {
    //Something in the case of admin
}

For Non-Administrators

if ( !current_user_can( 'manage_options' ) ) {
    //Something other than an administrator
}

Conditional branching between administrators and non-administrators

if ( current_user_can( 'manage_options' ) ) {
    //Something in the case of admin
} else {
    //Something other than an administrator
}

Avoid using the current_user_can function with a Role (administrator) as an parameter. It may return unintended results.

The usage of the current_user_can function is described in the following article.

Create Custom function

To create a Custom function to check if a user is an administrator, add the following code to functions.php in the theme.

function is_admin_user() {
    return current_user_can( 'manage_options' );
}

The following Custom functions are used

if( is_admin_user() ) {
    //Something in the case of admin
} else {
    //Something other than an administrator
}

Common Use Cases

Check to see if you are an administrator in the following cases

Most Popular Articles

  1. What’s new in WordPress 5.6? New Features and Changes
  2. How to Add width/height to Images in WordPress
  3. What’s New in WordPress 5.5.3? Fixed 1 Bug
  4. WordPress 5.6 jQuery version updates and solution for jQuery
  5. WordPress Version List (Release Date/Code Name)
  6. What’s new in WordPress 5.5? New Features and Changes
  7. What’s New in WordPress 5.5.2? Fixed 10 security issues
  8. How to check if the current user is Administrator in WordPress
  9. Vulnerability of File Manager WordPress plugin and Solutions
  10. Recommend Premium Themes for WordPress (By Usage)

New Articles

go to top