jQuery(document).ready(function() { // This is the script for uploading logos to the settings menu var _custom_media = true, _orig_send_attachment = wp.media.editor.send.attachment; jQuery('.uploader .button').click(function(e) { var send_attachment_bkp = wp.media.editor.send.attachment; var button = jQuery(this); var id = button.attr('id').replace('_button', ''); _custom_media = true; wp.media.editor.send.attachment = function(props, attachment){ if ( _custom_media ) { jQuery("#logo-input").val(attachment.url); jQuery("#logo-preview img").replaceWith(''); //console.log(attachment.url); } else { return _orig_send_attachment.apply( this, [props, attachment] ); }; } wp.media.editor.open(button); return false; }); jQuery('.add_media').on('click', function(){ _custom_media = false; }); jQuery("#logo-input").change(function() { var input = jQuery("#logo-input").val(); console.log(input); jQuery("#logo-preview").html(''); }); });