Skip to content

Instantly share code, notes, and snippets.

@bUxEE
Created November 18, 2016 23:48
Show Gist options
  • Save bUxEE/1f53af779909d29d79e49a81fcd29090 to your computer and use it in GitHub Desktop.
Save bUxEE/1f53af779909d29d79e49a81fcd29090 to your computer and use it in GitHub Desktop.
add image select to text input field
// IMAGE SELECT
jQuery(document).ready(function($) {
if ($('.wpt_set_custom_images').length > 0) {
if ( typeof wp !== 'undefined' && wp.media && wp.media.editor) {
$(document).on('click', '.wpt_set_custom_images', function(e) {
e.preventDefault();
var button = $(this);
var id = button.prev();
wp.media.editor.send.attachment = function(props, attachment) {
id.val(attachment.url);
};
wp.media.editor.open(button);
return false;
});
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment