How to add javascript to bottom of Wordpress "Edit Media" page?

I just want to add a snippet of JQuery to the bottom of the “Edit Media” page in the Wordpress dashboard. And only to that page only. Without modifiying core, of course.

Hmmmm… not sure how to do this exactly, but hope to give you a few pointers :slight_smile:

Assuming you know how to add jQuery to the bottom of pages using wp_enqueue_script & setting one of the variables to “true”, I’d also use something like to get the current screen of the page you’re looking at to determine the post type (which would be ‘attachment’ in your case) and what page you would be looking at (which I think will be post.php)

Hope that points you in the right direction!

Add this to your theme’s functions.php or in your plugin (or wherever)

add_action( 'admin_enqueue_scripts', function( $hook ) {
    if (
        $hook !== 'post.php' || $_GET['action'] !== 'edit'
        || ( strpos( $GLOBALS['post']->post_mime_type, 'image' ) === false && strpos( $GLOBALS['post']->post_mime_type, 'video' ) === false )
    ) {
   //its our page
    //enqueue script(s) using wp_enqueue_script()
} );

And then use wp_enqueue_script() to enqueue your script(s) in header/footer as you need. This will load the script(s) only on Edit Media screen in wp-admin and that too when media is either an image or video. If you need it for all types of media then replace the last condition block (one containing $GLOBALS[‘post’]->post_mime_type) with $GLOBALS[‘post’]->post_type !== ‘attachment’