Home » BLOG » WordPress » How to avoid jquery conflicts in WordPress

How to avoid jquery conflicts in WordPress

category:  WordPress, jQuery

WordPress developers know that the jQuery in WordPress runs in noConflict mode. This means when you enqueue the script that is dependent on jQuery in WordPress, you cannot use the common $ alias. To solve this issue, you can place your code using the $ shortcut inside a noConflict wrapper.

Here is an example.

  • in PHP file
 * enqueue jquery library from WordPress
  • in JS file
(function($) {
 // print out $
})( jQuery );

If you need to load the script in the header after the document is ready, you will use the code below.

jQuery(document).ready(function( $ ) {
 // print out $

It is an issue that some new WordPress developers don’t aware of it.