• Treebeard

    (@malawimama)


    I am using Slimmenu and I noticed that if I don’t load my own jquery from a CDN it doesn’t work at all. Anyone have a clue what the difference is between google’s jquery and the core jquery (other than the versions)? I’d like to stop loading google’s jquery but I can’t until I figure this out.

    All I know is that the core version is jQuery v1.12.4 and the CDN version I’m loading alongside it is jQuery v3.4.1 and that one works fine.

    Thanks!

    • This topic was modified 4 years ago by Treebeard.
Viewing 4 replies - 1 through 4 (of 4 total)
  • potentdevelopment

    (@potentdevelopment)

    The two versions of jQuery are massively different. Many methods that were available in 1.12.* have been deprecated or removed in version 3.*. Sounds like Slimemenu needs the latest jQuery.

    Also, the jQuery that WordPress loads in by default uses noConflict to jQuery instead of $. So if your trying to instantiate a plugin and using

    
    $(document).ready(function() {
        $('#whatever').someMethod(); //this will fail, you need to use
    })
    
    //This will work if your plugin is compatible with version 1.12.*
    jQuery(document).ready(function($) {
        $('#whatever').someMethod(); 
    })
    

    I’d look into one of the two items I listed above.

    Thread Starter Treebeard

    (@malawimama)

    Slimmenu doesn’t use either of those methods, it just goes right into the function. Anyway I found another issue with the WP core version too, my Advanced Custom Fields plugin doesn’t work the old version either. Even though I’m using if (! is_admin) to load the CDN version of jQuery, it seems that if I don’t deregister the core version in my functions file, ACF breaks too.

    Sounds like WordPress needs to update to the latest jQuery so people like me don’t have to keep loading a CDN version. I don’t really care, I was just hoping to get rid of those lines in my code and also stop worrying about that DEBUGGING notice on the login page (about deregister). It’s only there when I’m debugging so doesn’t matter, but just a thought.

    Nigel M Rodgers

    (@rodgersnigel)

    You can replace the core jQuery with a new version in a plugin or in your theme functions.php. You have to be absolutely sure there is no code using the legacy jQuery and take this into account whenever installing new plugins/themes. This is kind of bordering on bad practices but it’s the solution I would go with. That said here’s a snippet

    
    //Making jQuery Google API
    function modify_jquery() {
        if (!is_admin()) {
        // comment out the next two lines to load the local copy of jQuery
        wp_deregister_script('jquery');
        wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js', false, '3.4.1');
            wp_enqueue_script('jquery');
    }
    add_action('init', 'modify_jquery');
    

    You may replace the jQuery CDN with your own. Credit to WPBeginner the script snippet.

    Thread Starter Treebeard

    (@malawimama)

    Yes that’s the code I’ve always used in my themes, and thanks 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Core jquery doesn’t jive with Slimmenu’ is closed to new replies.