I want to have my plugin check if the user is anywhere in the Admin Panel (wp-admin) before executing a script. This would include:


Similar to using the using the global $pagenow:

global $pagenow;
if ( $pagenow == 'upload.php' ) {
    # do something if in the Media page

From doing some research, it looks like the get_current_screen() function is something I need, but this is what I've come up which doesn't work:

global $my_admin_page;
$screen = get_current_screen();
if ( $screen->id = $my_admin_page ) {
    return $content;
  • This question might help: wordpress.stackexchange.com/questions/106895/… Aug 30, 2016 at 23:05
  • 1
    You're looking for is_admin(). But beware it also includes admin-ajax.php unless you want that file included. For your page you might just check $_GET['page'] (options-general.php?page=?, admin.php?page=? ..)
    – Ismail
    Aug 30, 2016 at 23:34
  • @czerspalace and @SamuelElh both of you referring to the is_admin() helped. Thanks. Do either one of you want to post the answer for the credit and to quickly close this question? Otherwise I'll do it Aug 31, 2016 at 0:50

1 Answer 1


You can use the is_admin function. By definition, it checks "Whether the current request is for an administrative interface page."

You might also want to verify you are not doing an AJAX call by doing

if ( ! is_admin() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) ) {
    # code here...
  • Thanks for the answer. What's the reasoning to also check !DOING_AJAX? Is that to cover additional pages in the /wp-admin? Aug 31, 2016 at 15:54
  • 1
    As mentioned by @Samuel Elh, is_admin also is true when calling admin-ajax.php, which is used when making AJAX calls from both front-end and back-end. This way it won't return true for AJAX calls Aug 31, 2016 at 16:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.