Replace WordPress jQuery with CDN jQuery using wp_enqueue_script
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, but most of your plugins do.
WordPress scripts are registered on a script queue using tags. So, WordPress won’t load the same javascript library twice. If you want to change the default WordPress jQuery to google jQuery, just put the snippet below to your functions.php
file.
add_action('init', 'wpassist_register_theme_scripts'); function wpassist_register_theme_scripts(){ if(! is_admin()) { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js' ); wp_enqueue_script( 'jquery' ); wp_enqueue_script( 'theme-script', get_stylesheet_directory_uri() . '/scripts-directory/theme-script.js', array('jquery') ); } }
This code will tell WordPress to load google jQuery when a plugin needs that.
Deal Notice: We are using A2 hosting for all of our websites, and we are really happy with their service. So we wanted to share you this discount link for you to try it out. If you get a hosting using this link, you will also help us build better content for you: SSD Hosting - 300% Faster Than Standard Hard Drives