jQuery is not defined in Wordpress, but my script is enqueued properly

后端 未结 5 796
别跟我提以往
别跟我提以往 2020-12-31 02:19

I am trying to load a separate javascript file mobile-menu.js to my Wordpress theme. When I look at the console, it says, \"jQuery is not defined.\" However, I know that I e

5条回答
  •  佛祖请我去吃肉
    2020-12-31 02:37

    Wordpress ships with jQuery by default

    // Adds jQuery
        add_action('init', 'childoftwentyeleven_down');
    
            function childoftwentyeleven_down() {
    
              // register your script location, dependencies and version
                    wp_register_script('down',
                        get_stylesheet_directory_uri() . '/js/down.js',
                        array('jquery') );
               // enqueue the script
               wp_enqueue_script('down');
    
            }
    

提交回复
热议问题