jQuery(document).ready(function (c) { var a = true; var b = wp.media.editor.send.attachment; c(".upload_image_button").click(function (h) { var g = jQuery(this).parent(); var d = wp.media.editor.send.attachment; var f = c(this); a = true; wp.media.editor.send.attachment = function (e, i) { if (a) { g.find(".upload_image_field").val(i.url) } else { return b.apply(this, [e, i]) } }; wp.media.editor.open(f); return false }); jQuery(".add_media").on("click", function () { a = false }) });