Skip to content

Instantly share code, notes, and snippets.

@texe
Created July 18, 2022 10:11
Show Gist options
  • Save texe/f0e3acc3c3c60543d9588b1346544d9d to your computer and use it in GitHub Desktop.
Save texe/f0e3acc3c3c60543d9588b1346544d9d to your computer and use it in GitHub Desktop.
WordPress - remove version strings from CSS & JS link hrefs in WordPress
//Remove version strings from CSS and JS link hrefs
function ct_remove_version_strings( $src ) {
global $wp_version;
parse_str(parse_url($src, PHP_URL_QUERY), $query);
if ( !empty($query['ver']) && $query['ver'] === $wp_version ) {
$src = remove_query_arg('ver', $src);
}
return $src;
}
add_filter( 'script_loader_src', 'ct_remove_version_strings' );
add_filter( 'style_loader_src', 'ct_remove_version_strings' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment