var custom_uploader; jQuery('.uploadImageWP').click(function(e) { var custom_uploader = ""; e.preventDefault(); var target = jQuery(this).attr('data-target'); if (custom_uploader) { custom_uploader.open(); return; } custom_uploader = wp.media.frames.file_frame = wp.media({ title: 'Choose Image', button: { text: 'Choose Image' }, multiple: false }); //When a file is selected, grab the URL and set it as the text field's value custom_uploader.on('select', function() { attachment = custom_uploader.state().get('selection').first().toJSON(); jQuery(target).val(attachment.url); jQuery(target+"-preview").attr("src",attachment.url); }); custom_uploader.open(); }); jQuery('.deleteImageWP').click(function(e) { var target = jQuery(this).attr('data-target'); jQuery(target).val(""); jQuery(target+"-preview").hide(); }); (function( $ ) { // Add Color Picker to all inputs that have 'color-field' class $(function() { $('.css-pickup').wpColorPicker(); }); })( jQuery );