Skip to content

Instantly share code, notes, and snippets.

@rmpel
Last active October 7, 2019 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmpel/1e91a89ecf05d86794d3cb032708d653 to your computer and use it in GitHub Desktop.
Save rmpel/1e91a89ecf05d86794d3cb032708d653 to your computer and use it in GitHub Desktop.
The bestest way to change the jQuery version in WordPress
<?php
/**
* Attention all WordPress developers.
* NEVER EVER EVER DO THIS:
wp_deregister_script('jquery');
* AND I DO MEAN NEVER!!!!!
* Any plugin that has dependency on jQuery registered like
wp_register_script( 'a-script', .., .., deps: [ 'jquery ' ], ..);
* will now BREAK!!!!
* instead, do this:
*/
add_action('wp_head', function(){ // just in time (~PHP_INT_MAX === PHP_INT_MIN, a.k.a., firstest.)
global $wp_scripts;
$version = '3.4.1'; // the required jQuery version, check cdnjs for actually available.
$wp_scripts->registered['jquery-core']->ver = $version;
$wp_scripts->registered['jquery-core']->src = 'https://cdnjs.cloudflare.com/ajax/libs/jquery/'. $version .'/jquery.min.js';
}, ~PHP_INT_MAX);
just in case you think I made a typo:
bestest: absolute best
firstest: absolute first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment