Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I haven't had much chance to play with this, but for those looking to leverage the gallery element, this code should set you on your way.</p> <p>It is just a start point - it only provides a comma separated list of image id's, but that should be enough to start being creative.</p> <pre><code>&lt;input id="custom_media_id" type="text" name="attachment_id" value=""&gt; &lt;a href="#" class="button custom_media_upload" title="Add Media"&gt;Add Media&lt;/a&gt; &lt;script type="text/javascript"&gt; jQuery('.custom_media_upload').click(function() { var clone = wp.media.gallery.shortcode; wp.media.gallery.shortcode = function(attachments) { images = attachments.pluck('id'); jQuery('#custom_media_id').val(images); wp.media.gallery.shortcode = clone; var shortcode= new Object(); shortcode.string = function() {return ''}; return shortcode; } jQuery(this).blur(); // For Opera. See: http://core.trac.wordpress.org/ticket/22445 wp.media.editor.open(); return false; }); &lt;/script&gt; </code></pre> <p>This will populate the input field with a comma separated list of the image id's, in the order they were set in the editor (using the new drag and drop functionality).</p> <p>The function expects the shortcode to be sent back for placement in the main editor, but we don't want to do this, so we create a new object that returns a blank string for insertion.</p> <p>Also note, this doesn't handle inserting a single image as described above - it'll just put it into the post editor. So try combining the two listeners, or remove the appropriate tabs.</p> <p><strong>EDIT</strong></p> <p>Having spent some time looking at the core, I think this whole process can actually be done easier using the technique laid out <a href="https://stackoverflow.com/questions/13936080/pre-select-images-when-opening-wordpress-3-5-media-manager">here</a>, but as you'll read I haven't figured out yet how to pre-select the images when you reopen the media manager.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload