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

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.

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.

About Lars Koudal

1 Comment

Dex Barretton 15/02/2011 at 06:14

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.