How do I only load js on the post-new.php and post.php pages in admin?

Check the page and enqueue your script accordingly:

global $pagenow;
if (! empty($pagenow) && ('post-new.php' === $pagenow || 'post.php' === $pagenow ))
    add_action('admin_enqueue_scripts', 'enqueue_my_scripts');

function enqueue_my_scripts() {
    wp_enqueue_script(...);
} // function enqueue_my_scripts

Leave a Comment