Created
November 18, 2016 23:48
-
-
Save bUxEE/1f53af779909d29d79e49a81fcd29090 to your computer and use it in GitHub Desktop.
add image select to text input field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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