Replace Default WordPress jQuery Script with Google Library

By default, WordPress comes bundled with a bunch of libraries. These Libraries can be used while developing WordPress themes and plugins. One of the most common library used by developers is jQuery. In this post, we will see how we can replace the default jQuery library in WordPress with the one hosted on Google.

Useful Read: Do Something After WooCommerce Order is Completed

Why you should replace the default WordPress jQuery Library with the one hosted on Google?

Google hosted library is being used on a thousands of websites. Chances are your current visitor has also visited one of these websites. Hence, the visitor may not need to download jQuery at all as the script is already cached in his/her web browser making it load much faster.

To replace you self-hosted jQuery library with one hosted on Google, copy the following code and paste it inside your functions.php file located within your theme directory.

function replace_jquery() {
	if (!is_admin()) {
		// comment out the next two lines to load the local copy of jQuery
		wp_register_script('jquery', '', false, '1.11.1');
add_action('init', 'replace_jquery');



Leave a Comment.