is_admin()
Checks if the user is in the admin panel of the site (console or any other admin page). Conditional tag.
The function does not check if the user is authorized and if the user has the ability to view the admin panel. To check the user's capabilities, use current_user_can().
The function already works at a very early stage of loading: before any hook starts working, even before the constant SHORTINIT begins to work.
-
Returns false if attempted to use on the page /wp-login.php.
-
Returns true on ajax requests.
-
Returns true when calling load-scripts.php and load-styles.php.
- Not intended for use for security purposes. Always returns true when the current URL points to the admin part. Does not check if the user is authorized or if the user has access to the requested page. This function is created to check if in the admin panel and is not intended for securing requests.
1 time — 0.000014 sec (very fast) | 50000 times — 0.01 sec (speed of light) | PHP 7.0.14, WP 4.7
No Hooks.
Returns
true|false. Boolean: true if this is an admin page and false otherwise.
Usage
if( is_admin() ){
// ...
}
Examples
#1 An example of the definition of the front end and the admin area of the site:
if ( is_admin() ) {
echo 'You are in the admin area';
}
else {
echo 'You are browsing the front-end of the site (topic)';
}
Notes
- Global. WP_Screen.
$current_screenWordPress current screen object.
Changelog
| Since 1.5.1 | Introduced. |
is_admin() is admin code WP 6.9.1
function is_admin() {
if ( isset( $GLOBALS['current_screen'] ) ) {
return $GLOBALS['current_screen']->in_admin();
} elseif ( defined( 'WP_ADMIN' ) ) {
return WP_ADMIN;
}
return false;
}