Is there a way turn off jQuery.noConflict
in WordPress? I don’t mean loading an alternative version of jQuery or changing the loading method ie:
jQuery(document).ready(function( $ ) { ... });
or
(function($) { ... })( jQuery );
I mean is there a way to just turn off noConflict
mode for the version of jQuery bundled with WordPress?
Like would setting jQuery.noConflict(false)
work? If so, where would you set it?
After some research, this is the best answer I can give you:
To answer your other question, no you can’t pass in false, the attribute is used to control what happens to global variables. You can find the documentation here:
http://api.jquery.com/jQuery.noConflict/
Also note you could load 2 different versions of jQuery as it suggests (but is not recommended).
If you are including your own javascript library or scripts you can add the following to the very top:
I found another way of making the variable
$
available globally. Just put the following in your theme’s functions.php or in a plugin:This will output
$ = jQuery;
as an inline script immediately after the script tag for jQuery. So any scripts included after have the jQuery instance available as$
andjQuery
.Adding this worked for me finally:
You can add this in your header.php file in the head section:
Or if you use child theme, add that to functions.php in your child theme directory:
And create a main.js file in the same location as functions.php (in the child theme direcotry) and in that file add this:
You had better write in functions.php
function wp_deregister_script is for Remove a registered script.
When you use jQuery in WordPress
You can use jQuery like as usual.
Public document is here
https://developer.wordpress.org/reference/functions/wp_deregister_script/
To turn if off go to your
wp-includes/js/jquery/jquery.js
file and remove thejQuery.noConflict()
from the last line. Or as you suggested just set the boolean to false.That or you could replace the contents with a clean download from jquery.com, there is an intense debate going on in the trac.