Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sudipto-me/a130810af0ead2f6290d7e31ce34d20b to your computer and use it in GitHub Desktop.
Save sudipto-me/a130810af0ead2f6290d7e31ce34d20b to your computer and use it in GitHub Desktop.
This snippet gives the code for uploading image from media. This click event will open the media directory of the wordpress and gives u privilege to upload media image. Happy Coding. Peace
$('#similar_product_two_upload_image_button').on('click', function(e) {
e.preventDefault();
var send_attachment_bkp = wp.media.editor.send.attachment;
wp.media.editor.send.attachment = function(props, attachment) {
$('.similar_product_two_upload_src').attr('src', attachment.url);
$('#similar_product_two_upload_image').attr('value', attachment.url);
wp.media.editor.send.attachment = send_attachment_bkp;
}
wp.media.editor.open();
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment