0

I'm starting to get into WordPress and looking at developing some plugins.

If I want my plugin to use a specific version of jQuery how do I enable that?

ie. some themes don't use jQuery, some use OLD versions - what if I need a more recent version?

add_action( 'wp_enqueue_script', 'load_jquery' );
function load_jquery() {
    wp_enqueue_script( 'jquery' );
}

I've seen the code above suggested - but will that only load whatever jQuery is in the theme folders already (if at all)?

Is it better to include a jQuery.js file with my plugin, and reference it directly from my plugin code? If, so, how would I change the script above, to load MY version of jQuery?

Thank you for any help,

Mark

1 Answer 1

1

The latest WordPress 4.0 comes with jQuery 1.11.1.

But in case you want to remove the WordPress default jQuery library with say either a local new JS or a CDN you can do so by placing the following code in either a plugin or your theme's functions.php

function jquery_cdn() {
   if (!is_admin()) {
      wp_deregister_script('jquery');
      wp_register_script('jquery', 'jQuery_JS_PATH', false, '1.8.3');
      wp_enqueue_script('jquery');
   }
}
add_action('init', 'jquery_cdn');

References:

http://core.svn.wordpress.org/tags/4.0/wp-includes/js/jquery/

http://codex.wordpress.org/Function_Reference/wp_enqueue_script

http://agilewp.com/how-to/remove-wordpress-jquery-and-use-googles-cdn-version-instead/

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot for that. I wonder why WP comes with 1.11.1 when the latest version is 2.x - Cheers, Mark
jQuery 2.x does not have support for IE 6.7 and 8, which is why WordPress does not use it. Refer: jquery.com/download/#jquery-2-x
Some jQuery-dependent plugins (and probably many of them) won't work with such an old version of jQuery. What were they thinking? Why deliberately including an old version that will inevitably cause problems?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.