Query strings like ?ver=6.5.2 appended to CSS and JavaScript URLs are a common WordPress pattern used to bust browser caches when a file changes. Unfortunately, many caching proxies and CDNs refuse to cache resources that include a query string at all, which means every visitor downloads your scripts and stylesheets fresh on every page load. PageSpeed Insights and GTmetrix specifically flag this as a performance issue under the rule “Remove query strings from static resources.” Removing these version parameters forces proxies to cache the files by their URL alone, dramatically reducing load times on repeat visits. WordPress adds version strings automatically via wp_enqueue_script() and wp_enqueue_style(), so the cleanest way to strip them is with a filter on the generated HTML rather than touching individual enqueue calls. This approach works for both theme assets and plugin assets without requiring you to edit files you do not own. If you are serious about SEO, faster page loads lead directly to better Core Web Vitals scores, and that matters for rankings — pair this technique with canonical URL tags and Open Graph meta tags for a well-rounded on-page optimisation. The snippet below uses two filters to strip query strings from both script and style src attributes. It is safe to use with most caching plugins because they operate at a different layer. Test on staging before applying to production, especially if you rely on plugin auto-updates that ship new asset versions.
Problem: WordPress appends ?ver=X.X to every enqueued script and stylesheet URL, preventing CDNs and proxies from caching those files effectively.
Solution: Add the following code to your functions.php file:
/**
* Remove query strings from static CSS and JS resources.
*/
add_filter( 'style_loader_src', 'helloadmin_remove_query_strings', 999 );
add_filter( 'script_loader_src', 'helloadmin_remove_query_strings', 999 );
function helloadmin_remove_query_strings( $src ) {
if ( ! is_admin() ) {
$src = preg_replace( '/\?ver=[0-9a-z\.\-]+$/i', '', $src );
}
return $src;
}
// Optional: also strip the ?ver= from the middle of a URL (before a & param)
add_filter( 'style_loader_src', 'helloadmin_remove_query_strings_mid', 999 );
add_filter( 'script_loader_src', 'helloadmin_remove_query_strings_mid', 999 );
function helloadmin_remove_query_strings_mid( $src ) {
if ( ! is_admin() ) {
$parts = explode( '?ver=', $src );
if ( isset( $parts[1] ) ) {
// Preserve any extra query params after the version value
$remainder = preg_replace( '/^[^&]+/', '', $parts[1] );
$src = $parts[0] . ( $remainder ? '?' . ltrim( $remainder, '&' ) : '' );
}
}
return $src;
}
NOTE: Do not apply this filter inside the admin area (is_admin() check is included). If you use a CDN with cache invalidation based on URL parameters, test thoroughly — stripping version strings means a CSS change will only propagate when the CDN cache expires naturally or is manually purged. You can also accomplish this without code using caching plugins such as W3 Total Cache or WP Rocket, which have a built-in “remove query strings” toggle.