• Resolved Ate Up With Motor

    (@ate-up-with-motor)


    I have a plugin that uses the Google Hosted Libraries version of JQuery, and I would like to instead use the WordPress core libraries. Is it possible, without forking the plugin, to unqueue the Google scripts from functions.php and enqueue the local ones instead? I’ve seen various tutorials about going the other way, but not removing Google libraries.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator Steven Stern (sterndata)

    (@sterndata)

    Volunteer Forum Moderator

    Moderator bcworkz

    (@bcworkz)

    If the plugin has correctly registered and enqueued its jquery, then switching is the exact opposite of the tutorials you’ve seen. Be sure you code hooks “wp_enqueue_scripts” (for front end jQuery) after the plugin does. Deregister and dequeue the plugin’s scripts, then register and enqueue the local version using the same handle, normally 'jquery'.

    It’s a little convoluted as the plugin has probably also deregistered and dequeued the native jquery to do what it does. Check to see if there is a filter or some hook in the plugin to prevent this from happening in the first place. If possible, it’s better than letting the plugin override, then undoing the override with your own.

    Thread Starter Ate Up With Motor

    (@ate-up-with-motor)

    Check to see if there is a filter or some hook in the plugin to prevent this from happening in the first place. If possible, it’s better than letting the plugin override, then undoing the override with your own.

    This is an excellent point. I’ll have a look at the plugin and see if I can make sense of what it’s doing.

    @sterndata — I’ll have a look at that, thanks!

    Thread Starter Ate Up With Motor

    (@ate-up-with-motor)

    @bcworkz Okay, I looked through the plugin code, and I don’t see any indication of it deregistering or dequeuing the native library. In fact, if I’m understanding correctly, it’s enqueuing certain things remotely and enqueuing several others from the local library.

    What it’s enqueuing is a jQuery UI library (specifically https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js) that doesn’t appear to have a local equivalent in the core wp-includes\js\jquery\ folder. I’m not familiar enough with jQuery to know exactly what it is, but it looks like a concatenated, minified version of the the library in the core jQuery folder. If so, replacing it might be more complicated than just registering and queuing a different script.

    There’s also a separate HTML script tag that references https://code.jquery.com/ui/1.12.1/jquery-ui.js as the source, but it’s not registered or enqueued; I assume the src attribute means it’s running that script directly from the jQuery CDN, but I’m not sure. If it is doing that directly, that means I can’t substitute a local script through functions.php and would have to fork the plugin to get rid of it, doesn’t it?

    Moderator bcworkz

    (@bcworkz)

    The local jQuery UI is /wp-includes/js/jquery/ui/jquery.ui.core.min.js, registered as ‘jquery-ui-core’. Yes, you cannot mix versions in various modules, they all need to come from the same source.

    The script tag on the page had to come from somewhere. If it’s not enqueued to have WP output the reference, then what ever is doing it is doing it wrong. Sadly, it’s not all that unusual. There’s an off chance the responsible code includes a filter hook where we could alter the reference. But since they didn’t bother to enqueue, I doubt they’d provide a hook. If the link is hard coded into the plugin you have little choice but to directly alter the plugin code, or find a different plugin.

    Thread Starter Ate Up With Motor

    (@ate-up-with-motor)

    Okay, I was afraid of that. @bcworkz, thanks a lot for your input here — I understand what’s going on a little better than I did before, which is definitely useful.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Switching to native JQuery’ is closed to new replies.