201611.27
Désactivé
0

JQuery and dollar($)

To use jQuery in your plugins and themes "The Right Way" all you need to do is enqueue it (probably in your functions.php file):

wp_enqueue_script("jquery");

I'm not sure this is neccessary but here for completness.

f the script is being loaded in the footer (which you should be doing in the vast majority of cases) you can wrap the code in an anonymous function (technically any IIFE (404 link removed 2015/03/04)) where you pass in jQuery to be mapped to $.

(function($) {
	
	// $ Works! You can test it with next line if you like
	// console.log($);
	
})( jQuery );

If you absolutely need to load the scripts in the header, you'll probably need to use a document ready function anyway, so you can just pass in $ there.

jQuery(document).ready(function( $ ) {
	
	// $ Works! You can test it with next line if you like
	// console.log($);
	
});

Go forth and write nice looking jQuery!

Source : https://digwp.com/2011/09/using-instead-of-jquery-in-wordpress/

By : Chris Coyier