Using multiple versions of jQuery while still calling it like WP likes

I have two JS plugins inside my plugin. One uses jQuery 1.7.1 and the other 1.9.1.

I need to have each of them use different version. This is how things are at the moment:

Plugin php file:

wp_register_script('jq-1.9.1-js', 'https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js');
wp_enqueue_script('jq-1.9.1-js');
wp_register_script('jq-1.7.1-js', 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js');
wp_enqueue_script('jq-1.7.1-js');

Plugin JS file:

    var $j = jQuery.noConflict();

    $j(document).ready(function() {
    // plugin 1
    $j('.someClass').plugin1({
        // options
    });
    // plugin 2
    $j('.someClass').plugin2({
        // options
    });
}

I searched Google quite a lot and saw solutions for multiple versions but they did not take into account the proper way of including scripts in WP (the use of register and enqueue).

How do I use two versions of jQuery for two JS plugins while still calling scripts the WP way?

Thanks

1 Answer
1

I found that it was better for me to use the latest jQuery version (which WordPress loads by default) and to treat the incompatibility issue by modifying the JS plugin files that were incompatible with the latest jQuery version.

Note: The reason I chose this solution is because in most cases, JS plugin incompatibility with newer jQuery versions is a result of a use of a deprecated method or function in the code and usually replacing the call with a call to an existing function/method will solve the issue and exempt you from including redundant jQuery scripts.

Furthermore, if the plugin will get updated in the future, you should have no problem update the one you currently using because the newer version would probably support the latest jQuery version.

Leave a Comment