I'm implementing a gallery upload to my plugin, and I've set up an image gallery upload with:

function upload_gallery_button(e) {
    var $input_field = $('#portfolio_gallery');
    var ids = $input_field.val();
    var gallerysc = '[gallery ids="' + ids + '" link="file"]';
    wp.media.gallery.edit(gallerysc).on('update', function(g) {
        var id_array = [];
        $.each(g.models, function(id, img){
        var ids = id_array.join(",");
        ids = ids.replace(/,\s*$/, "");

When I click on upload button, the gallery upload opens, I select the images, and in my hidden input field I get the id's of the images that I can put in the gallery shortcode. But this only works when I save my page. Is it possible to pull the url's of the selected images so that the images are added instantly?

I don't need the gallery shortcode, I can create my own html markup for images in the metabox, but I'd like to have images shown as I add them.

I've tried changing id_array.push(img.id); to id_array.push(img.link); and id_array.push(img.url); but no luck.

The information on this is sparse, so any help is appreciated.

1 Answer 1


Found it:


This will return url's instead of id's.

  • Another option is img.get('url') May 25, 2015 at 13:47

Your Answer

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

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