Jquery requires jQuery instead of $

I am working on a WordPress theme and I have included jQuery,

// Waves wp_enqueue_style( 'APKMirror-wave', get_template_directory_uri() . '/inc/waves/waves.min.css'); wp_enqueue_script( 'APKMirror-wave', get_stylesheet_directory_uri() . '/inc/waves/waves.min.js', array( 'jquery' ) ); // Boostrap wp_enqueue_style( 'APKMirror-Bootstrap', get_template_directory_uri() . '/inc/bootstrap/bootstrap.min.css'); wp_enqueue_script( 'APKMirror-Bootstrap', get_stylesheet_directory_uri() . '/inc/bootstrap/bootstrap.min.js', array( 'jquery' ) ); 

The problem is that every time I run jQuery code, I have to type the word "jQuery" and not just use $. How can I change my code to use $?

0
source share
1 answer

jQuery in WordPress works in noConflict mode, which means that the global $ shortcut for jQuery is not available. Use a ready-made document that allows $ to be used as an alias for jQuery.

 jQuery(document).ready(function($) { // Inside here $ can be used instead of jQuery. }); 

or

 (function($) { // Use $ here. })(jQuery); 

Thanks to Paulpro for correctly indicating that there is an alternative that can be used if you need to run a script before the rest of the DOM loads.

+6
source

Source: https://habr.com/ru/post/979552/


All Articles