I have created a WordPress file uploader. Its like when i click on add media button it takes me to add media uploader. But when i choose the image it doesn’t get inserted into the field. I want whenever i choose an image and click on insert button, image URL should get inserted into the text editor.
var image_field;
jQuery(function($){
$(document).on('click', 'input.select-img', function(evt){
image_field = $(this).siblings('.img');
check_flag=1;
tb_show('', 'media-upload.php?type=image&TB_iframe=true');
window.send_to_editor = function(html) {
imgurl = $('img', html).attr('src');
image_field.val(imgurl);
tb_remove();
}
return false;
});
});
Include jquery library if you dn’t have.
Please include the below jquery code, where you are adding the HTML code.
Jquery:
HTML:
Include the below PHP code in your theme function.php file.
PHP:
Important Note:
Before click insert button. Please confirm the Image URL is displaying in the text filed. Please see the screenshot