Warning: You shouldn’t replace core jQuery version, especially in the admin panel. Since many WordPress core functionality may depend on the version. Also, other plugin may depend on the
jQuery
version added in the core.
If you are sure that you want to change the core jQuery
version, in that case you may add the following CODE in your active theme’s functions.php
file (even better if you create a plugin for this):
function replace_core_jquery_version() {
wp_deregister_script( 'jquery' );
// Change the URL if you want to load a local copy of jQuery from your own server.
wp_register_script( 'jquery', "https://code.jquery.com/jquery-3.1.1.min.js", array(), '3.1.1' );
}
add_action( 'wp_enqueue_scripts', 'replace_core_jquery_version' );
This will replace core jQuery
version and instead load version 3.1.1
from Google’s server.
Also, although not recommended, you may use the following additional line of CODE to replace the jQuery version in wp-admin
as well:
add_action( 'admin_enqueue_scripts', 'replace_core_jquery_version' );
This way, even after updating WordPress, you’ll have the version of jQuery
as you want.
A slightly better function:
The replace_core_jquery_version
function above also removes jquery-migrate
script added by WordPress core. This is reasonable, because the newest version of jQuery will not work properly with an older version of jquery-migrate
. However, you can include a newer version of jquery-migrate
as well. In that case, use the following function instead:
function replace_core_jquery_version() {
wp_deregister_script( 'jquery-core' );
wp_register_script( 'jquery-core', "https://code.jquery.com/jquery-3.1.1.min.js", array(), '3.1.1' );
wp_deregister_script( 'jquery-migrate' );
wp_register_script( 'jquery-migrate', "https://code.jquery.com/jquery-migrate-3.0.0.min.js", array(), '3.0.0' );
}