Skip to content

Instantly share code, notes, and snippets.

@nullvariable
Created August 20, 2019 20:32
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 nullvariable/c7a306c0b28a1d5841120297a9ec7da9 to your computer and use it in GitHub Desktop.
Save nullvariable/c7a306c0b28a1d5841120297a9ec7da9 to your computer and use it in GitHub Desktop.
Remove query strings from WordPress static assets
<?php
function remove_query_strings() {
if(!is_admin()) {
add_filter('script_loader_src', 'strip_query_string', 15);
add_filter('style_loader_src', 'strip_query_string', 15);
}
}
function strip_query_string($src){
$output = preg_split("/(&ver|\?ver)/", $src);
return $output[0];
}
add_action('init', 'remove_query_strings');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment