wppaste
WordPress

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.

Get the current screen object

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?

The $current_screen global is only populated in wp-admin, after WordPress builds a WP_Screen object for the loaded admin page. Front-end requests, most REST API requests, and many AJAX calls never set it, so the instanceof check in the source falls through and returns null.

Why does get_current_screen() return null even though I'm in wp-admin?

It's being called before the screen has been established. The global is populated once the current_screen action fires, so calling the function during plugins_loaded, admin_menu, or earlier still finds $current_screen unset.

How do I read the post type of the current admin screen?

get_current_screen() gives you the whole WP_Screen object, not just an ID, so the post type lives on a property of that object rather than being returned directly.

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

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
4

Executed per call on PHP 8.5. The body compiles to 5.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
37

37 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.

WhenInstructionsCalls it makes
always4none

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 · 37

Show all 37

Source code

function get_current_screen() {	global $current_screen; 	if ( ! $current_screen instanceof WP_Screen ) {		return null;	} 	return $current_screen;}

Changelog

Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 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.