Basic Admin Detection
is_admin() // Returns true for ANY admin page (including AJAX requests)
Check Specific Admin Pages
// For plugin/theme options pages
function is_my_plugin_admin_page() {
$screen = get_current_screen();
return ($screen->base === 'toplevel_page_my-plugin-slug');
}
// For post type edit screens
function is_custom_post_edit_screen() {
$screen = get_current_screen();
return ($screen->post_type === 'my_cpt' && $screen->base === 'post');
}
📋 Post Editor Conditions
Post Type Editor
function is_post_editor() {
global $pagenow;
return (is_admin() && $pagenow === 'post.php');
}
function is_new_post_screen() {
global $pagenow;
return (is_admin() && $pagenow === 'post-new.php');
}
Gutenberg vs Classic Editor
function is_gutenberg_editor() {
$screen = get_current_screen();
return method_exists($screen, 'is_block_editor') && $screen->is_block_editor();
}
🗂️ List Table Screens
Post List Table
function is_post_list_table() {
global $pagenow;
return (is_admin() && $pagenow === 'edit.php');
}
// For custom post types
function is_custom_post_list() {
$screen = get_current_screen();
return ($screen->base === 'edit' && $screen->post_type === 'my_cpt');
}
⚙️ Special Admin Pages
Plugin/Theme Admin Pages
function is_plugins_page() {
global $pagenow;
return (is_admin() && $pagenow === 'plugins.php');
}
function is_theme_customizer() {
global $pagenow;
return (is_admin() && $pagenow === 'customize.php');
}
User Profile Screen
function is_user_profile_page() {
global $pagenow;
return (is_admin() && ($pagenow === 'profile.php' || $pagenow === 'user-edit.php'));
}
🛡️ Advanced Conditional Checks
Combined with Hook Suffixes
add_action('admin_enqueue_scripts', function($hook) {
// Only load on our plugin's settings page
if ($hook !== 'toplevel_page_my-plugin-slug') return;
wp_enqueue_script('my-admin-script');
});
Checking Admin AJAX Requests
function is_my_plugin_ajax() {
return (defined('DOING_AJAX') && DOING_AJAX &&
isset($_REQUEST['action']) &&
strpos($_REQUEST['action'], 'myplugin_') === 0);
}
Admin Area with GET/POST Parameters
function is_specific_admin_context() {
return (is_admin() &&
isset($_GET['page']) &&
$_GET['page'] === 'my-plugin-page' &&
isset($_GET['tab']) &&
$_GET['tab'] === 'advanced');
}
if (!current_user_can('edit_posts')) return;
is_network_admin() // Multisite only
add_action('admin_footer', function() {
echo '<pre>'.print_r(get_current_screen(), true).'</pre>';
});