is_admin(): bool

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 Conditional Tags article in the Theme Developer Handbook.

Return

bool True if inside WordPress administration interface, false otherwise.

Source

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

	return false;
}

Changelog

VersionDescription
1.5.1Introduced.

User Contributed Notes

  1. Skip to note 8 content

    Example:

    if ( ! is_admin() ) {
        // Runs only if this PHP code is in a file that displays outside the admin panels, like the theme template.
        echo '<div style="text-align: center">Welcome to our website.</div>';
    } else {
        // Runs only if this code is in a file that displays inside the admin panels, like a plugin file.
        echo '<div style="text-align: center">Welcome to your Admin Panels.</div>';
    }
  2. Skip to note 11 content

    is_admin() returns true for Ajax requests, since wp-admin/admin-ajax.php defines the WP_ADMIN constant as true.

  3. Skip to note 12 content

    Note that is_admin() is available much earlier in the WordPress load sequence than other Conditional Tags and can be used before the main query has been run. This means it can be used in both the Theme functions.php file and in Plugins without needing to hook into an action or filter that triggers later.

You must log in before being able to contribute a note or feedback.