Skip to content

Instantly share code, notes, and snippets.

@petersplugins
Created November 14, 2016 15:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petersplugins/4d438a47f79007de68bd91f06e5afcad to your computer and use it in GitHub Desktop.
Save petersplugins/4d438a47f79007de68bd91f06e5afcad to your computer and use it in GitHub Desktop.
<?php
// This code snippet replaces the link to the locally hosted jQuery core with the link to the jQuery core hosted on jQuery CDN
// This reduces server load and page load time
// We do not use wp_deregister_script and wp_register_script but we directly access the global variable $wp_scripts
// because we want to replace the script with the correct version number
add_action( 'wp_print_scripts', 'replace_jquery' );
function replace_jquery() {
global $wp_scripts;
$wp_scripts->registered['jquery-core']->src = 'https://code.jquery.com/jquery-' . $wp_scripts->registered['jquery-core']->ver . '.min.js';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment