I use this after I checked if the user is admin

   if ( isset($_GET['action'])  && $_GET['action'] === 'edit' )

is there better way?

3

You can use get_current_screen to determine this.

$screen = get_current_screen();
if ( $screen->parent_base == 'edit' ) {
    echo 'edit screen';
}

I don’t know if I exactly would say this is always better, it depends on what’s needed, but it’s probably the way I’d do it. The big benefit with this method is that you get access to more information and ergo can do more and different distinctions. Just take a look at the documentation to understand what I mean.

It should be used in later hooks, Codex says:

The function returns null if called from the admin_init hook. It
should be OK to use in a later hook such as current_screen.

Tags:

Leave a Reply

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