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
}
Call
What 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
Parameter
Description
None
This function takes no parameters.
Return Value
Return Value
Description
bool
true 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.
On the public site (is_admin() is false):
<!-- front-end script loaded -->
In the dashboard (is_admin() is true):
(nothing is printed)
How It Works
is_admin() is false on the public site.
! is_admin() turns that into true, so the code runs.
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>';
} );
}
Output
In wp-admin (true):
<div class="notice notice-info"><p>Theme is active.</p></div>
On the public site (false):
(the hook is never added)
How It Works
The if runs when the request is for wp-admin.
Only then is the admin_notices hook added.
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.';
}
Output
Administrator viewing the front page:
You are an administrator.
Administrator viewing Dashboard > Posts:
You are in the dashboard.
You are an administrator.
Subscriber viewing the front page:
(nothing is printed)
How It Works
is_admin() checks the screen.
current_user_can() checks the person.
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.