Last active
October 7, 2019 10:09
-
-
Save rmpel/1e91a89ecf05d86794d3cb032708d653 to your computer and use it in GitHub Desktop.
The bestest way to change the jQuery version in WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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