SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist artcoder's Avatar
    Join Date
    Aug 2005
    Location
    Planet Earth
    Posts
    598
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

  2. #2
    SitePoint Member
    Join Date
    Dec 2003
    Location
    Manchester UK
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmmmm... not sure how to do this exactly, but hope to give you a few pointers

    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 http://codex.wordpress.org/Function_...current_screen 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!
    Hi! I'm Rhys Wynne and I wrote bbPress Complete
    Author+ Premium Wordpress Plugin - Use Code FORUM10 for 10% Off!
    WP Email Capture - Build Your List From Inside Wordpress
    Follow Me on Twitter

  3. #3
    SitePoint Wizard silver trophybronze trophy asp_funda's Avatar
    Join Date
    Jun 2003
    Location
    ether
    Posts
    4,479
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Add this to your theme's functions.php or in your plugin (or wherever)

    PHP Code:

    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 )
        ) {
            return;
        }
     
       
    //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'
    Our lives teach us who we are.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Me - Photo Blog - Personal Blog - Dev Blog
    iG:Syntax Hiliter -- Colourize your code in WordPress!!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •