WordPress: Specify a different version of jQuery with wp_enqueue_script()

I find using the wp_enqueue_script function a nice tidy way to include javascript files in my theme. Especially when using scripts that come bundled with WordPress, such as jQuery, script.aculo.us, etc. However I recently had an issue with the very cool Fancybox jQuery plugin not playing nice with the version of jQuery that shipped with WordPress. Here’s the solution.

You essentially need to tell WordPress to use a different version, by way of the functions wp_deregister_script and wp_register_script.

FYI at the time of writing, I’m using Fancybox Version 1.3.4 which plays nice with jQuery 1.4.3

Here’s the PHP code to go in your functions.php:

function my_enqueue_scripts() {
	wp_deregister_script('jquery');
	wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js');
	wp_enqueue_script('jquery');
}
 
add_action('wp_enqueue_scripts', 'my_enqueue_scripts');

For more information on wp_enqueue_script, see the codex:
http://codex.wordpress.org/Function_Reference/wp_enqueue_script

Check out Fancybox – jQuery Plugin here:
http://fancybox.net

Comments are closed.