admin管理员组

文章数量:1208155

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);

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);
Share Improve this question edited Feb 9, 2022 at 0:02 ratib90486 asked Feb 8, 2022 at 14:39 ratib90486ratib90486 295 bronze badges 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 Commented 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 Commented 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 Commented Feb 9, 2022 at 0:33
Add a comment  | 

1 Answer 1

Reset to default 0

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

本文标签: jquerywp not defined at wpUploaderprototype