0

I'm confused with this command in my functions.php file:

function Remove_JQuery_Migrate( &$scripts) {
    if(!is_admin()) {
        $scripts->remove( 'jquery');
        $scripts->add( 'jquery', false, array( 'jquery-core' ), '3.2.1' );
    }
}
add_filter( 'wp_default_scripts', 'Remove_JQuery_Migrate' );

I understand that this loads JQuery throughout my website - but here's the odd thing, if I change the version of JQuery is does NOT update.

If I change the version of any other .css or .js file then that forces the update but the version of JQuery will not be updated.

I've repeatedly tried to clear the cache (I am using CloudFlare, maxCDN and W3TC) and no joy.

Does anyone have any idea of how I can problem solve here?

My client-facing problem is this, if you click on my website and select any event you'll notice that the dropdown doesn't work.

https://infosec-conferences.com/

The developer console gives the error:

Uncaught TypeError: $ is not a function

That error I am sure is because JQuery is not being called correctly...

Any ideas of what I should do?

1

I understand that this loads JQuery throughout my website - but here's the odd thing, if I change the version of JQuery is does NOT update.

It's not odd. You can't load arbitrary versions of jQuery by changing the version argument. From the documentation for wp_enqueue_script(), that version number is:

String specifying script version number, if it has one, which is added to the URL as a query string for cache busting purposes. If version is set to false, a version number is automatically added equal to current installed WordPress version. If set to null, no version is added.

So it's just for telling WordPress which version number to append to the URL. If you're loading an already registered script it's only going to load the version bundled with WordPress (currently 1.12.4).

But your issue has nothing to do with the version of jQuery being loaded. The issue is that WordPress runs jQuery in 'no conflict' mode. This just means that jQuery is not assigned to $. Instead you need to access it with jQuery. So if you're running jQuery code in WordPress you either need to replace all your uses of $ with jQuery, or wrap your code in this:

(function($) {
// Your code here
})(jQuery)

This will make jQuery available as $ for your code.

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.