Note that there are some explanatory texts on larger screens.

plurals
  1. POWordpress 3.5 custom media upload for your theme options
    primarykey
    data
    text
    <p>Wordpress 3.5 has been released recently, I used the Wordpress Media Upload system via thickbox and <code>window.send_to_editor</code> for some options in my Wordpress theme (backgrounds, logos etc...).</p> <p>But as you know Wordpress has integrated a new Media Manager, I wanted to used this new feature to upload images/files as custom fields. So I spent the morning to find a way to get the wished result.</p> <p>I found with this solution, which can be useful for some of you. Thanks to give me your feedback on the code or any improvements you have in mind!</p> <p>HTML Sample:</p> <pre><code>&lt;a href="#" class="custom_media_upload"&gt;Upload&lt;/a&gt; &lt;img class="custom_media_image" src="" /&gt; &lt;input class="custom_media_url" type="text" name="attachment_url" value=""&gt; &lt;input class="custom_media_id" type="text" name="attachment_id" value=""&gt; </code></pre> <p>jQuery Code:</p> <pre><code>$('.custom_media_upload').click(function() { var send_attachment_bkp = wp.media.editor.send.attachment; wp.media.editor.send.attachment = function(props, attachment) { $('.custom_media_image').attr('src', attachment.url); $('.custom_media_url').val(attachment.url); $('.custom_media_id').val(attachment.id); wp.media.editor.send.attachment = send_attachment_bkp; } wp.media.editor.open(); return false; }); </code></pre> <p>If you want to see every settings contained in the <code>attachment</code> variable you can do a <code>console.log(attachment)</code> or <code>alert(attachment)</code>.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

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