WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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);


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.

share|improve this question
up vote 1 down vote accepted

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

share|improve this answer
Hi mate, thanks for that. I've already tried SLT's plugin but its "Remove" upload functionality isn't clear to the user: it doesn't remove the preview image, it just clears the hidden input's value: // Wipe form values when remove checkboxes are checked $( '.slt-fs-button:first' ).parents( 'form' ).submit( function() { $( '.slt-fs-remove:checked' ).each( function() { $( this ).siblings( 'input.slt-fs-value' ).val( '' ); }); }); If you have any idea how to solve that, you'd be a lifesaver! – dunc Jul 2 '11 at 17:14

It's more a hack than a solution. You could use a regex to extract the attachment ID from the wp-image- class. Add the following snippet to your window.send_to_editor function.

$classes = jQuery('img', html).attr('class');
$id = $classes.replace(/(.*?)wp-image-/, '');
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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