get_current_screen(): WP_Screen|null

Get the current screen object

Return

WP_Screen|null Current screen object or null when screen not defined.

Source

function get_current_screen() {
	global $current_screen;

	if ( ! isset( $current_screen ) ) {
		return null;
	}

	return $current_screen;
}

Changelog

VersionDescription
3.1.0Introduced.

User Contributed Notes

  1. Skip to note 11 content
    PAGE               $SCREEN_ID           FILE
    -----------------  -------------------  -----------------------
    Media Library      upload               upload.php
    Comments           edit-comments        edit-comments.php
    Tags               edit-post_tag        edit-tags.php
    Plugins            plugins              plugins.php
    Links              link-manager         link-manager.php
    Users              users                users.php
    Posts              edit-post            edit.php
    Pages              edit-page            edit.php
    Edit Site: Themes  site-themes-network  network/site-themes.php
    Themes             themes-network       network/themes
    Users              users-network        network/users
    Edit Site: Users   site-users-network   network/site-users
    Sites              sites-network        network/sites
  2. Skip to note 12 content

    Be aware the this function doesn’t always exist, something that @ravanh had sort of eluded to. It isn’t loaded and available until after admin_init has fired. It is advisable to check whether the function exists when using it within any hooks in the even those hooks fire before that function is actually loaded and available to use.

        /**
         * Check whether the get_current_screen function exists
         * because it is loaded only after 'admin_init' hook.
         */
        if ( function_exists( 'get_current_screen' ) ) {
            $current_screen = get_current_screen();
            // Do your thing.
        }