wppaste
WordPress

is_admin(): bool

Since
1.5.1
Source
wp-includes/load.php:1327

Reports whether the current request is being handled inside the wp-admin area rather than the public-facing site. It relies on the global current_screen object once WordPress has set it, falling back to the WP_ADMIN constant earlier in the load order. It does not tell you anything about the logged-in user's role, so pair it with current_user_can() when a permission check is what you actually need.

Determines whether the current request is for an administrative interface page.

Description

Does not check if the user is an administrator; use current_user_can() for checking roles and capabilities.

For more information on this and similar theme functions, check out the https://developer.wordpress.org/themes/basics/conditional-tags/ Conditional Tags article in the Theme Developer Handbook.

Compatibility

WordPress
since 1.5.1
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Return value

bool
True if inside WordPress administration interface, false otherwise.

Code examples

Every example is editable and runs in a real WordPress booted in your browser by WordPress Playground. Press Run, then edit the code: clicking away re-runs it. Nothing is sent anywhere until you do.

Branch logic based on whether the current request is in wp-admin

A plugin function that behaves differently depending on where it's called from during a single page load.

if ( is_admin() ) {
	echo esc_html( 'Currently loading the WordPress dashboard.' );
} else {
	echo esc_html( 'Currently loading a front-end page (or admin-ajax.php).' );
	$price = get_post_meta( 2, 'price', true );
	printf( 'Front-end context; post 2 price meta is %s.', esc_html( $price ) );
}

Print an is_admin() status message on front-end page loads

A plugin that hooks wp_footer to show whether the visitor is on the front end, useful when debugging code that behaves differently in the dashboard.

add_action( 'wp_footer', 'wppaste_show_admin_context' );

function wppaste_show_admin_context() {
	echo '<p>' . esc_html( 'is_admin() returned: ' . ( is_admin() ? 'true' : 'false' ) ) . '</p>';
}

Visit a front-end post (post ID 1, "Hello world!") to see the message printed near the closing body tag.

Common problems and fixes · 4

Why does is_admin() return true for every logged-in user instead of just administrators?

is_admin() only checks whether the current screen or the WP_ADMIN constant marks the request as an administration page; it never looks at the user's role or capabilities.

Why is is_admin() true inside my admin-ajax.php handler even though it's not a dashboard page?

admin-ajax.php lives under wp-admin, so WP_ADMIN is defined and is_admin() returns true for every AJAX request, whether triggered from the dashboard or the front end. - Combine it with wp_doing_ajax() when you need to tell the two apart - Check the referring page or a custom parameter if the distinction matters to your logic

Why does is_admin() return true on Network Admin or User Admin screens too, not just the normal dashboard?

is_admin() calls WP_Screen::in_admin() with no argument, which reports true for any admin context, including the network admin and the user's personal admin area, not only wp-admin/. - Use is_network_admin() to detect the network admin screens specifically - Use is_user_admin() to detect the user's personal admin area

Why did is_admin() return false when I called it very early in the request?

Before $GLOBALS['current_screen'] is set, is_admin() falls back to the WP_ADMIN constant; if that constant isn't defined yet at the point your code runs, the function returns false by default.

Alternatives and related functions

current_user_can
When you need to check the logged-in user's role or capability rather than which side of the site is loading.
wp_doing_ajax
When the request might be an AJAX call and you need to distinguish that from a normal dashboard page load.
is_network_admin
When you specifically need to detect the Network Admin screens rather than any admin context.
is_user_admin
When you specifically need to detect the logged-in user's personal admin area rather than the main dashboard.

Performance profile

How much work a call to is_admin() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
5–6

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 11.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
50

50 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 2 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost is_admin() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
!isset($value)5–6none
isset($value)6->in_admin()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev115–62
8.5115–62
8.4115–62
8.3115–62
8.2115–62
8.1115–622 fewer instructions than PHP 7.4
7.4136–82

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Used by · 50

Show all 50

Source code

function is_admin() {	if ( isset( $GLOBALS['current_screen'] ) ) {		return $GLOBALS['current_screen']->in_admin();	} elseif ( defined( 'WP_ADMIN' ) ) {		return WP_ADMIN;	} 	return false;}

Changelog

Introduced in 1.5.1. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.7.7 tag, from src/wp-includes/load.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.