0

I followed this code as below but it gives me the error "wp not defined". I placed the code inside footer.php in my child theme and also in functions.php but both are erroneous.

(function($){

    $.extend( wp.Uploader.prototype, {
        success : function( file_attachment ){
            console.log( file_attachment );
        }
    });
})(jQuery);
3
  • 1
    you need to enqueue the necessary scripts, none of the code in the question you linked to is a complete example and will not work on its own, that's why it says wp is not defined, because the rest of the code is missing and wasn't mentioned in the question. They only shared the parts they were having problems with
    – Tom J Nowell
    Feb 8, 2022 at 16:44
  • @TomJNowell I was assuming jquery is already loaded by WP by default. So, really, that's all I have in my footer.php or functions.php other than other child theme functions. Or must I load the code in a non-child theme?
    – ratib90486
    Feb 9, 2022 at 0:02
  • 1
    jQuery probably is loaded already, but it's not jQuery that's missing, wp is missing, and wp.Uploader. The media library scripts don't get loaded on the frontend unless you make the effort to enqueue them. The Q you tried to use only has small snippets of a much larger piece of code that wasn't shared, including some PHP in a plugin or function.php file. That question cannot be used as an example of how to create an uploader on the frontend, or how to load the media library
    – Tom J Nowell
    Feb 9, 2022 at 0:33

1 Answer 1

0

I solved the problem by loading the code inside footer.php of my child theme. Thanks people for all the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.