Reputation: 7818
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
Upvotes: 0
Views: 390
Reputation: 11808
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/
Upvotes: 1