How to Check if I’m on a Custom Post Type Archive in the Admin Area

In WordPress, the phrase “custom post type archive” usually describes the front-end archive page for a post type. In the admin area, the equivalent screen is the list table for that post type, such as edit.php?post_type=book. If you are adding admin notices, loading scripts, or changing columns, you often need to detect that exact screen.

The safest tool is get_current_screen(). It returns a WP_Screen object that describes the current admin page. For a custom post type list table, the screen ID is normally edit-{post_type}, and the post_type property contains the post type name.

add_action('current_screen', function ($screen) {
    if (!$screen instanceof WP_Screen) {
        return;
    }

    if ($screen->id === 'edit-book' && $screen->post_type === 'book') {
        // You are on the admin list table for the "book" post type.
    }
});

If you want a reusable helper, wrap the check in a small function. This keeps conditions readable when the same logic is needed in multiple hooks.

function my_is_admin_post_type_list($post_type) {
    if (!is_admin()) {
        return false;
    }

    $screen = function_exists('get_current_screen') ? get_current_screen() : null;

    return $screen instanceof WP_Screen
        && $screen->base === 'edit'
        && $screen->post_type === $post_type;
}

You can then use the helper when enqueueing scripts or showing admin-only UI. The admin_enqueue_scripts hook is a common place for this because the current screen is already available.

add_action('admin_enqueue_scripts', function () {
    if (!my_is_admin_post_type_list('book')) {
        return;
    }

    wp_enqueue_script(
        'book-admin-tools',
        plugin_dir_url(__FILE__) . 'book-admin-tools.js',
        array('jquery'),
        '1.0.0',
        true
    );
});

Avoid relying only on $_GET['post_type']. It works in many cases, but it is less expressive and easier to misuse. For the default Posts screen, WordPress may omit post_type from the URL entirely. get_current_screen() gives you a normalized view of the admin page instead of making you reverse-engineer the request.

If the check runs too early, get_current_screen() may not be available yet. Put screen-dependent logic inside hooks such as current_screen, load-edit.php, or admin_enqueue_scripts. That keeps the code aligned with WordPress admin loading order and avoids false negatives during plugin initialization.

Also remember that admin list tables are not the same as front-end post type archives. On the front end, you would use conditional tags such as is_post_type_archive('book'). Inside wp-admin, use WP_Screen and check for the edit base plus the expected custom post type.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x