get_current_screen(): WP_Screen|null
- Since
- 3.1.0
- Source
wp-admin/includes/screen.php:224
Retrieves the WP_Screen object WordPress stored in the global $current_screen, returning null when no screen has been set yet. It is only reliable inside wp-admin once the current_screen action has fired, so calling it from plugins_loaded, the front end, or admin-ajax.php requests usually yields null. Pair it with an instanceof WP_Screen check before reading properties like id, base, or post_type.
Compatibility
- WordPress
- since 3.1.0
- 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
WP_Screen|null- Current screen object or null when screen not defined.
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.
Show the current admin screen ID in an admin notice
Print the screen's id and base on every wp-admin page load so you can see which screen WordPress thinks you're on.
add_action( 'admin_notices', function() {
$screen = get_current_screen();
if ( $screen instanceof WP_Screen ) {
printf(
'<div class="notice notice-info"><p>%s</p></div>',
esc_html( 'Current screen ID: ' . $screen->id . ' (base: ' . $screen->base . ')' )
);
} else {
echo '<div class="notice notice-warning"><p>' . esc_html( 'No screen object available.' ) . '</p></div>';
}
} );The notice appears on every admin screen, so you'll see a different id/base combination depending on which wp-admin page loads it.
Run code only on the Posts list table screen
Check the screen id returned by get_current_screen() so a notice only appears on edit.php and not on other admin pages.
add_action( 'admin_notices', function() {
$screen = get_current_screen();
if ( $screen instanceof WP_Screen && 'edit-post' === $screen->id ) {
echo '<div class="notice notice-success"><p>' . esc_html( 'You are viewing the Posts list table.' ) . '</p></div>';
}
} );Load wp-admin/edit.php to see the notice; it stays silent on every other admin screen.
Common problems and fixes · 3
- Why does get_current_screen() return null on my site's front end?
- Why does get_current_screen() return null even though I'm in wp-admin?
- How do I read the post type of the current admin screen?
Why does get_current_screen() return null on my site's front end?
Why does get_current_screen() return null even though I'm in wp-admin?
How do I read the post type of the current admin screen?
Alternatives and related functions
WP_Screen::get- When you need a WP_Screen object for an arbitrary screen hook name or id, not necessarily the one currently loaded.
set_current_screen- When you need to manually establish the global $current_screen yourself, such as in a cron job or CLI context where the usual admin bootstrap never runs.
is_admin- When you only need to know whether the request is inside wp-admin at all, rather than which specific screen is loaded.
Performance profile
How much work a call to get_current_screen() 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
- 4
- Plugin surface
- None
- Called by
- 34
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. The body compiles to 5.
Nothing here hands control to plugin code.
34 places in core call this, so the cost is paid more often than your own code shows.
What one call costs · 1 distinct outcome
One number would be a lie: the work depends on which branch runs. These are every distinct cost get_current_screen() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 4 | none |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 5 instructions, 4 executed per call, 1 branch. The work does not change between versions.
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 · 34
- Custom_Background::admin_load()Sets up the enqueue for the CSS & JavaScript files.
- Custom_Image_Header::help()Adds contextual help.
- WP_Plugin_Dependencies::display_admin_notice_for_unmet_dependencies()Displays an admin notice if dependencies are not installed.
- WP_Privacy_Policy_Content::notice()Adds a notice with a link to the guide when editing the privacy policy page.
- WP_Privacy_Policy_Content::policy_text_changed_notice()Outputs a warning when some privacy info has changed.
- WP_Screen::get()Fetches a screen object.
- WP_Screen::render_view_mode()Renders the list table view mode preferences.
- WP_Site_Health::admin_body_class()Adds a class to the body HTML tag.
- WP_Site_Health::enqueue_scripts()Enqueues the site health scripts.
- WP_Widget_Custom_HTML::add_help_text()Add help text to widgets admin screen.
- _get_list_table()Fetches an instance of a WP_List_Table class.
- _wp_privacy_settings_filter_draft_page_titles()Appends '(Draft)' to draft page titles in the privacy page dropdown so that unpublished content is obvious.
Show all 34
- add_meta_box()Adds a meta box to one or more screens.
- add_screen_option()Register and configure an admin screen option
- do_accordion_sections()Meta Box Accordion Template Function.
- do_meta_boxes()Meta-Box template function.
- iframe_header()Generic Iframe header for use with Thickbox.
- page_attributes_meta_box()Displays page attributes form fields.
- post_comment_meta_box()Displays comments for post.
- remove_meta_box()Removes a meta box from one or more screens.
- screen_layout()Returns the screen layout options.
- screen_meta()Renders the screen's help.
- screen_options()Returns the screen's per-page options.
- twentyeleven_theme_options_help()
- twentyfourteen_contextual_help()Add contextual help to the Themes and Post edit screens.
- wp_add_dashboard_widget()Adds a new dashboard widget.
- wp_admin_bar_edit_menu()Provides an edit link for posts and terms.
- wp_ajax_search_install_plugins()Handles searching plugins to install via AJAX.
- wp_ajax_search_plugins()Handles searching plugins via AJAX.
- wp_auth_check_load()Loads the auth check for monitoring whether the user is still logged in.
- wp_dashboard()Displays the dashboard.
- wp_dashboard_setup()Registers dashboard widgets.
- wp_global_styles_render_svg_filters()Renders the SVG filters supplied by theme.json.
- wp_plugin_update_row()Displays update information for a plugin.
Source code
function get_current_screen() { global $current_screen; if ( ! isset( $current_screen ) ) { return null; } return $current_screen;}Changelog
Introduced in 3.1.0. 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-admin/includes/screen.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.