$current_screen WordPress Global Variable

For highly customized WordPress installations is can be useful to have specific instructions in usage for specific pages. These instructions could be in the form of a FAQ, a step-by-step instruction list, a helpful flash-animation, there are several options available.

For specific targeting of instructions we can use  $current_screen to detect where the user is.

$current_screen

I stumbled into the $current_screen global variable by chance, looking for something else in the WordPress source code. This little documented global variable contains information about which page specifically you are currently viewing in the WordPress administration interface.

Using this variable you can either embed the necessary code in a plugin, or as I prefer, modify the WordPress theme’s functions.php file.

Example Code

add_action('admin_notices', 'notifications');

/**
*
* notifications() - Administration Header Instructions and Notifications
*
*/
function notifications() {
global $current_screen;

if ($current_screen->id=='dashboard') ) {
echo "<div id='notice_dashboard' class='updated fade'><p>Welcome to your blog!</p></div>";
}
}

Welcome to your blog!

The code above shows a simple “Welcome to your blog!” if you are on the dashboard page. You can target other specific pages by changing the look-up on $current_screen->id to another value. You can use the reference table I created below.

Notice that I have added a unique css id identifier to the the <div>-tag. By doing this it I am able to style pages individually if I need to.

Read also  WordPress Multisite Search

Another example usage could be to remind authors to make sure they have chosen a category and tagged posts before they publish.

if ($current_screen-&amp;gt;id=='post') ) {
			echo &amp;quot;&amp;lt;div id='notice_post' class='updated fade'&amp;gt;&amp;lt;p&amp;gt;Please remember to choose both a CATEGORY and to TAG the post before you publish!&amp;lt;/p&amp;gt;&amp;lt;/div&amp;gt;&amp;quot;;
}

Reference Table

I created the following reference table to help other developers who want to create super targeted instructions in their WordPress installations.

Main Menu Submenu $current_screen->id
Super Admin ms-admin
Sites ms-sites
Users ms-users
Themes ms-themes
Options ms-options
Update ms-upgrade-network
Dashbord dashboard
My Sites my-sites
Updates update-core
Posts edit-post
Add New post
Categories edit-category
Post Tags edit-post_tag
Media
Library upload
Add New media
Links
Links link-manager
Add New link
Link Categories edit-link-categories
Pages
Pages edit-page
Add New page
Comments edit-comments
Appearance
Themes (Manage) themes
Themes (install) theme-install
Widgets widgets
Menus nav-menus
Editor theme-editor
Plugins
Plugins plugins
Add New plugin-install
Editor plugin-editor
Users
Users users
Add New user
Your Profile profile
Tools tools
Import import
Export export
Network network
Settings
General options-general
Writing options-writing
Reading options-reading
Discussion options-discussion
Media options-media
Privacy options-privacy
Permalinks options-permalink

1 thought on “$current_screen WordPress Global Variable”

  1. Dex Barrett

    You’re right, this is not a well documented feature, which amazes me since is very common in plugin development to check which page you are visiting. Anyway, thank you very much for posting this, especially the reference table. This is pure gold.

Leave a Comment

Your email address will not be published. Required fields are marked *