is_admin(): bool
- Since
- 1.5.1
- Source
wp-includes/load.php:1352
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.
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?
- Why is is_admin() true inside my admin-ajax.php handler even though it's not a dashboard page?
- Why does is_admin() return true on Network Admin or User Admin screens too, not just the normal dashboard?
- Why did is_admin() return false when I called it very early in the request?
Why does is_admin() return true for every logged-in user instead of just administrators?
Why is is_admin() true inside my admin-ajax.php handler even though it's not a dashboard page?
Why does is_admin() return true on Network Admin or User Admin screens too, not just the normal dashboard?
Why did is_admin() return false when I called it very early in the request?
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
- Scaling
- Constant
- Instructions
- 5–6
- Plugin surface
- None
- Called by
- 50
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 11.
Nothing here hands control to plugin code.
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.
| When | Instructions | Calls it makes |
|---|---|---|
!isset($value) | 5–6 | none |
isset($value) | 6 | ->in_admin() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 11 | 5–6 | 2 | |
| 8.5 | 11 | 5–6 | 2 | |
| 8.4 | 11 | 5–6 | 2 | |
| 8.3 | 11 | 5–6 | 2 | |
| 8.2 | 11 | 5–6 | 2 | |
| 8.1 | 11 | 5–6 | 2 | 2 fewer instructions than PHP 7.4 |
| 7.4 | 13 | 6–8 | 2 |
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
- Featured_Content::hide_featured_term()Hide featured tag from displaying when global terms are queried from the front end.
- Featured_Content::hide_the_featured_term()Hide featured tag from display when terms associated with a post object are queried from the front end.
- Twenty_Twenty_One_Dark_Mode::the_html()Prints the dark-mode switch HTML.
- WP::handle_404()Set the Headers for 404, if nothing is found for requested URL.
- WP::parse_request()Parses the request to find the correct WordPress query.
- WP_Admin_Bar::_render()
- WP_Customize_Manager::establish_loaded_changeset()Establishes the loaded changeset.
- WP_Customize_Manager::wp_loaded()Registers styles/scripts and initialize the preview of each setting
- WP_Customize_Manager::wp_redirect_status()Prevents Ajax requests from following redirects when previewing a theme by issuing a 200 response instead of a 30x.
- WP_Customize_Nav_Menu_Item_Setting::sort_wp_get_nav_menu_items()Re-apply the tail logic also applied on $items by wp_get_nav_menu_items().
- WP_Customize_Widgets::schedule_customize_register()Ensures widgets are available for all types of previews.
- WP_Fatal_Error_Handler::handle()Runs the shutdown handler.
Show all 50
- WP_Font_Face::__construct()Creates and initializes an instance of WP_Font_Face.
- WP_Plugin_Dependencies::get_dependency_api_data()Retrieves and stores dependency plugin data from the WordPress.org Plugin API.
- WP_Post_Type::add_rewrite_rules()Adds the necessary rewrite rules for the post type.
- WP_Post_Type::set_props()Sets post type properties.
- WP_Query::parse_query()Parses a query string and sets query type booleans.
- WP_REST_Site_Health_Controller::load_admin_textdomain()Loads the admin textdomain for Site Health tests.
- WP_Site_Health::check_wp_version_check_exists()Tests whether `wp_version_check` is blocked.
- WP_Styles::__construct()Constructor.
- WP_Taxonomy::add_rewrite_rules()Adds the necessary rewrite rules for the taxonomy.
- WP_Taxonomy::set_props()Sets taxonomy properties.
- WP_Theme::get_allowed_on_site()Returns array of stylesheet names of themes allowed on the site.
- _WP_Editors::editor_js()Print (output) the TinyMCE configuration and initialization scripts.
- _WP_Editors::editor_settings()
- _WP_Editors::enqueue_default_editor()Enqueue all editor scripts.
- _custom_header_background_just_in_time()Registers the internal custom header and background routines.
- _post_format_request()Filters the request to allow for the format prefix.
- _wp_customize_include()Includes and instantiates the WP_Customize_Manager class.
- _wp_theme_json_webfonts_handler()Runs the theme.json webfonts handler.
- determine_locale()Determines the current locale desired for the request.
- dynamic_sidebar()Displays dynamic sidebar.
- get_pagenum_link()Retrieves the link for a page number.
- get_post_class()Retrieves an array of the class names for the post container element.
- get_rest_url()Retrieves the URL to a REST endpoint on a site.
- get_the_title()Retrieves the post title.
- get_theme_mods()Retrieves all theme modifications.
- image_constrain_size_for_editor()Scales down the default size of an image.
- is_admin_bar_showing()Determines whether the admin bar should be showing.
- is_protected_endpoint()Determines whether we are currently on an endpoint that should be protected against WSODs.
- load_default_textdomain()Loads default translated strings based on locale.
- ms_not_installed()Displays a failure message.
- redirect_canonical()Redirects incoming links to the proper URL based on the site url.
- remove_editor_styles()Removes all visual editor stylesheets.
- render_block_core_categories()Renders the `core/categories` block on server.
- script_concat_settings()Determines the concatenation and compression settings for scripts and styles.
- switch_theme()Switches the theme.
- twenty_twenty_one_continue_reading_link()Creates the continue reading link.
- twenty_twenty_one_continue_reading_link_excerpt()Creates the continue reading link for excerpt.
- twenty_twenty_one_get_attachment_image_attributes()Filters the list of attachment image attributes.
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.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.8.8 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.