Using the WordPress Media Library and returning the Attachment ID rather than URL?

I’m currently using some JS to pop open the WordPress Media Library in a thickbox container and return the URL of a selected image, then display it.

window.send_to_editor = function(html) {
    imgurl = jQuery('img',html).attr('src');
    jQuery('#upload_image-' + id_to_pass).val(imgurl);

    output_code="<img class="media_display" src="" + imgurl + '" />';
    jQuery(output_code).appendTo('#media_display-' + id_to_pass);

    tb_remove();
}

I was wondering if it’s possible to return the attachment ID instead?

I would like to use the image’s description and caption fields, which I won’t be able to do (easily) if I can only access the image URL from the Media Library.

2 Answers
2

Take a look at this http://sltaylor.co.uk/blog/hijacking-the-wordpress-media-library-overlay/

Leave a Comment