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

后端 未结 5 795
别跟我提以往
别跟我提以往 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:46

    You can try:

    enqueue Jquery first.

    wp_enqueue_script('jquery'); 
    

    and then enqueuing the latter script with JQuery dependency in 3rd argument i.e array('jquery') that's what mostly people forget.

    wp_enqueue_script( 'lapetitefrog-mobile-menu', get_template_directory_uri() . '/js/mobile-menu.js', array('jquery'), '1.0', true );
    

提交回复
热议问题