how to know if admin is in edit page or post [duplicate]

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.

Leave a Comment