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. Vulnerability of File Manager WordPress plugin and Solutions
  2. What’s new in WordPress 5.5? New Features and Changes
  3. How to use the current_user_can function in WordPress
  4. What is WordPress’ server requirement? Support for Each Version
  5. What is WordPress? Guide for beginners
  6. How to check if the current user is Administrator in WordPress
  7. WordPress Version List (Release Date/Code Name)
  8. What’s new in WordPress 5.5.1? 44 bugs fixed

New Articles

go to top