i got a problem with custom add media button wordpress when trying to insert to post. when i tried insert to post from url the image wasn’t show ( undefined result not an url image ) but if i choose from media library then i press “insert to post” it was work.
here is my code :
jQuery('.upload_image #upload_image_button').click(function() {
formfield = jQuery('#upload_image').attr('name');
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
targetInput = jQuery(this).next('input');
previewImage = jQuery(this).prev('div');
window.send_to_editor = function(html) {
imgurl = jQuery('img',html).attr('src');
targetInput.val(imgurl);
previewImage.html('<img src="' + imgurl + '" width="100px" height="100px" />');
tb_remove();
}
return false;
});
and here is my html :
<ul class="prev-thumb">
<li class="upload_image">
<div class="preview-image"><?php echo(isset($images[0])) ? '<img src="'.$images[0].'" width="100px" height="100px" />' : ''; ?></div>
<input class="button button-primary button-large" id="upload_image_button" value="Upload Image" type="button" />
<input id="upload_image" size="36" name="item[images][]" type="hidden" />
</li >
<li class="upload_image">
<div class="preview-image"><?php echo(isset($images[1])) ? '<img src="'.$images[1].'" width="100px" height="100px" />' : ''; ?></div>
<input class="button button-primary button-large" id="upload_image_button" value="Upload Image" type="button" />
<input id="upload_image" size="36" name="item[images][]" type="hidden" />
</li >
<li class="upload_image">
<div class="preview-image"><?php echo(isset($images[2])) ? '<img src="'.$images[2].'" width="100px" height="100px" />' : ''; ?></div>
<input class="button button-primary button-large" id="upload_image_button" value="Upload Image" type="button" />
<input id="upload_image" size="36" name="item[images][]" type="hidden" />
</li >
<li class="upload_image">
<div class="preview-image"><?php echo(isset($images[3])) ? '<img src="'.$images[3].'" width="100px" height="100px" />' : ''; ?></div>
<input class="button button-primary button-large" id="upload_image_button" value="Upload Image" type="button" />
<input id="upload_image" size="36" name="item[images][]" type="hidden" />
</li >
</ul>
sorry for my english and thanks in advance, i’m new here 🙂