How to isolate code to the post edit screen

Posted by Prem Tiwari | Updated on

Use the WP_Screen object to tell where you are at in the admin instead. Much more convenient.

Note that you have to wait until at least the admin_head hook to run for the current screen to have been determined and the WP_Screen object to therefore have been initialized. The current screen is not yet set at plugin load, or even at init.

You can use this to see the various properties that the screen object will have on various pages in the admin:

’,
) );
}

This will add a new section to the Help dropdown in WordPress, dumping the screen object into it as a “Screen Info” tab. Handy, and makes it easy to figure out the unique properties for each admin screen.


If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.

Related Questions & Answers