Is it necessary to enqueue jquery? I think sometring is wrong because it won't work without adding this line


I do not think I needed before I am pretty sure jquery is already in the wordpress core.

 function mis_cursos_all_user_scripts()  
    // defer o async
    add_filter( 'script_loader_tag', 'mscrss_add_defer_attribute', 10, 2    );
    wp_register_script('vimeo', 'https://player.vimeo.com/api/player.js', array(),'jquery'); 
    // error test is not enqueued in video pages! ojo
    wp_enqueue_script( 'mis_cursos_user_scripts_video', plugin_dir_url( __FILE__ ) . 'mis-cursos-videos.js', array( 'vimeo'), null, false  ); 
    wp_enqueue_script( 'mis_cursos_user_scripts_test', plugin_dir_url( __FILE__ ) . 'mis-cursos-test.js', array( 'jquery'), null, false  ); 
    wp_localize_script( 'mis_cursos_user_scripts_video', 'mis_cursos_video_namespace', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );           
    wp_localize_script( 'mis_cursos_user_scripts_test', 'mis_cursos_test_namespace', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );     
add_action( 'wp_enqueue_scripts', 'mis_cursos_all_user_scripts' ); 

Not at all. The 3rd argument of wp_enqueue_script() is the script's dependencies. All you have to do, is to pass jquery to it, and WordPress will automatically enqueue jQuery for you.

  • But, I did it , see this line here: wp_enqueue_script( 'mis_cursos_user_scripts_test', plugin_dir_url( FILE ) . 'mis-cursos-test.js', array( 'jquery'), null, false ); – user2088350 Nov 15 '17 at 9:38
  • You are right. Now it works after updating Wordpress. Maybe the failure was caused by some error Beta testing Wordpress in my local server. Thanks. – user2088350 Nov 15 '17 at 10:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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