What I am trying to do is -

1) User clicks "Add Media"

2) Select an image

3) Image uploads finishes

4) Now it should insert into post automatically without pressing "Insert into post".

Anywhere to hook, and click the "Insert into post" using jquery.

Any clues ?

  • The code for the media library is not fun to work with - trust me. Nov 1, 2014 at 22:30
  • you're right, I am looking for any hack though. Nov 2, 2014 at 4:52

1 Answer 1


The hook for doing stuff after an upload is the reset event on wp.Uploader.queue triggered by the pluploader when it's finished (see line 249 in "wp-includes/js/plupload/wp-plupload.js"). Here's one hack to use this to do an auto-insert after an upload:

function wpse167143_admin_footer() {
jQuery( document ).ready(function() {
    typeof wp.Uploader !== 'undefined' && wp.Uploader.queue.on( 'reset', function () {
        // From the primary toolbar (".media-toolbar-primary")
        // get the insert button view (".media-button-insert")
        // and execute its click (as specified in its options).
    } );
add_action( 'admin_footer' , 'wpse167143_admin_footer' );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.