WordPress is_admin() Function

Beginner
4 min read
Updated: Nov 2026
3 examples
Conditional tag

Definition

In WordPress, is_admin() returns true when the current request is for the admin area, which means any screen under wp-admin. On the public site it returns false.

The name is easy to misread. It does not check if the user is an administrator. A visitor with the Administrator role who views the front page still gets false.

Syntax

Use it as the test of an if statement.

WordPress
if ( is_admin() ) {
  // code for the true path
} else {
  // code for the false path
}
CallWhat it does
is_admin()True inside the dashboard, such as Posts, Plugins, or Settings.
! is_admin()True on the public site. Often used to load front-end scripts.
current_user_can( 'manage_options' )Use this instead when you want to check the user role or capability.

Calls to admin-ajax.php also return true, even when they come from the front end.

Full declaration
WordPress
is_admin(): bool

Parameters

ParameterDescription
NoneThis function takes no parameters.

Return Value

Return ValueDescription
booltrue if the request is for the admin dashboard, otherwise false.

WordPress Examples

Three short theme examples. Each one shows what prints on the true path and the false path.

Example 1 — Run code only on the public site

Load a front-end script only when you are not in the dashboard.

WordPress
function mytheme_scripts() {
  if ( ! is_admin() ) {
    echo '<!-- front-end script loaded -->';
  }
}
add_action( 'wp_head', 'mytheme_scripts' );

How It Works

  1. is_admin() is false on the public site.
  2. ! is_admin() turns that into true, so the code runs.
  3. In wp-admin the check fails and nothing is printed.

Example 2 — Run code only in the dashboard

Add an admin notice only inside wp-admin.

WordPress
if ( is_admin() ) {
  add_action( 'admin_notices', function () {
    echo '<div class="notice notice-info"><p>Theme is active.</p></div>';
  } );
}

How It Works

  1. The if runs when the request is for wp-admin.
  2. Only then is the admin_notices hook added.
  3. Visitors on the front end never run this code.

Example 3 — Admin screen vs administrator role

See the difference between a place and a person.

WordPress
<?php
if ( is_admin() ) {
  echo 'You are in the dashboard.';
}
if ( current_user_can( 'manage_options' ) ) {
  echo 'You are an administrator.';
}

How It Works

  1. is_admin() checks the screen.
  2. current_user_can() checks the person.
  3. They answer two different questions, so use the one you need.

Frequently Asked Questions

It returns true or false (a bool). Use it inside an if statement.
No. It checks if the request is for the admin area. Use current_user_can( 'manage_options' ) to check the role.
Yes, requests to admin-ajax.php return true even if the AJAX call started on the front end. Use wp_doing_ajax() to tell them apart.
Yes. It does not need the main query, so it works as soon as WordPress knows the request type.

Next: is_archive()

Check if the current page is any kind of archive.

is_archive() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful