Skip to content

Instantly share code, notes, and snippets.

@brianleejackson
Last active December 25, 2023 19:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brianleejackson/51150fd569816a40457c1cc83eda68bc to your computer and use it in GitHub Desktop.
Save brianleejackson/51150fd569816a40457c1cc83eda68bc to your computer and use it in GitHub Desktop.
Remove query strings from static resources in WordPress. Source: https://perfmatters.io/docs/remove-query-strings-from-static-resources/
/* Remove Query Strings
/***********************************************************************/
add_action('init', 'remove_query_strings');
function remove_query_strings() {
if(!is_admin()) {
add_filter('script_loader_src', 'remove_query_strings_split', 15);
add_filter('style_loader_src', 'remove_query_strings_split', 15);
}
}
function remove_query_strings_split($src) {
//strip query strings
$output = preg_split("/(&ver|\?ver)/", $src);
return $output[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment