HowTo: Replace WordPress self hosted jQuery with Google jQuery

If your hosting server is not fast enough, you may want to replace your self-hosted #jquery with google cdn hosted jquery. You may think that you are not using that script anyways, but most of your #plugins do.

WordPress scripts are registered onto queue using tags. So, WordPress won’t load same javascript library twice. If you want to change default WordPress jQuery to google jQuery, just put the snippet below to your functions.php file.

function shailan_register_theme_scripts(){
	// wp_enqueue_script( 'jquery' );
	if(! is_admin()) {
		wp_deregister_script( 'jquery' ); 
		wp_register_script( 'jquery', '' );
		// wp_enqueue_script( 'jquery' );
		// wp_enqueue_script( 'some-script-using-jquery', get_stylesheet_directory_uri() . '/scripts-directory/somescript.js', array('jquery') ); 
} add_action('init', 'shailan_register_theme_scripts');

This code will tell WordPress to load google jQuery, when a plugin needs that. That’s all folks.