Simple/basic use of get_current_screen

I haven’t tested this but theoretically you could do something like this (Using the Codex as an Example):

function load_custom_wp_admin_style() {
    $pageArr = array(1, 2, 3);
    if(isset($_GET['post']) && in_array($_GET['post'], $pageArr)){
        wp_register_style( 'custom_wp_admin_css', get_template_directory_uri() . '/admin-style.css', false, '1.0.0' );
        wp_enqueue_style( 'custom_wp_admin_css' );
    }
}
add_action( 'admin_enqueue_scripts', 'load_custom_wp_admin_style' );

We get the current screen and set the page IDs we would like to include any scripts or styles. We then make sure that there is a $_GET['post'] set which holds our post->ID and we also want to make sure we’re in the correct post type (though you could probably skip the whole current screen thing entirely and just use $_GET). We then check to see if the current post ID is in our array of accepted IDs and if so: enqueue.

Leave a Comment

tech