Top of page

Remove Query Strings From WordPress CSS and JavaScript Resources

Varmapublished on August 29, 2017 & last updated on January 18, 2022

There is some small quick fix which can bring some heavy performance improvement to your WordPress website. One such fix is to remove query strings from your WordPress static resources like CSS and JavaScript. Normally, if you check your WordPress website source code, the CSS and JavaScript files will have a version tag and number at the end of the URLs. For example, something.com/style.css?ver=1.1.0. Due to this version string at end of the static resources, some proxy caching servers and CDNs are unable to cache those files. This, in turn, will affect your WordPress site loading time and hit heavily on performance.

On a side note, developers usually use versioning of files when making changes to CSS or JavaScript files. This allows them to easily push an update for the resources without forcing you to flush the cache. The whole version control is part of the developer's workflow.

Well, as most of us are running a WordPress for personal blogging or building custom websites, we usually don't need the versioning of the static files. Here's how to remove query strings from your WordPress static resources or CSS and JavaScript files.

Remove Query String from WordPress static files with custom code

One of the easiest ways, if you have little technical knowledge, is to add custom code in your themes function.php file to remove query string static resources in WordPress. Note that if not properly done, it will break your WordPress website.

/*
Remove version query strings from CSS and JS links
*/

function tf_remove_script_version( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', 'tf_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', 'tf_remove_script_version', 15, 1 );

If everything is done correctly, on reloading your WordPress website and checking the source code, you won't see those version number at the end of the static files. This will also fix the warnings you get when checking WordPress website in Pingdom or Google PageSpeed insight called "Remove query strings from static resources".

Remove Query Strings From WordPress CSS and JavaScript Resources

Remove Query String from WordPress static files with Plugin

Well, if you are a little bit afraid to edit those WordPress theme files, then there are WordPress Plugins for your help. One such free plugin is the Query Strings Remover By Atul Kumar Pandey. Once installed, the plugin can instantly remove query strings (like "?" and "&") from your WordPress static resources like CSS and JavaScript files. There isn't much to configure in the plugin. You just need to install the plugin on your WordPress site and you're good to go.

If you are looking to further speed up your WordPress website and remove the performance hitting barriers, then you could try the premium Perfmatters WordPress plugin. It's a lightweight WordPress performance plugin that can speed up your WordPress site by reducing HTTP requests, stripping out code, and minimizing back-end load. The query strings removal from WordPress static resources is just one out of its feature-rich list. Other performance guaranteed feature of Perfmatters plugin include -

  • Disable emojis, embeds, RSS feeds, XML-RPC, scripts per page/post, WordPress Heartbeat API, self pingbacks.
  • Remove jQuery migrate, WordPress version number, wlwmanifest link, RSD link, RSS feed links, REST API links.
  • Disable and Limit Post Revisions.
  • Change the autosave interval.
Remove Query String from WordPress static files with Perfmatters premium plugin

With Perfmatters WordPress plugin installed you no longer need to mess around with WordPress source code or your theme functions.php file. Every feature can be enabled or disabled with a single toggle or click. One good thing about the plugin is that there is a handy tooltip next to each optimization feature that links to Perfmatters knowledge base article. This allows you to learn more about the feature, how it could help in optimizing your WordPress website and its adverse effects if any.

In Perfmatters WordPress Performance Plugin

Flat 10% OFF on Perfmatters WordPress Performance Plugin

Get flat 10 per cent discount on Perfmatters WordPress Performance Plugin.

10% OFF Coupon
PERFMATTERS CopyGet this deal

In Jetpack

Flat 40% OFF on WordPress Jetpack plans

Get flat 40 per cent discount on WordPress Jetpack automated real-time backups. security scan and other premium plans. Jetpack Security pack provides easy-to-use, comprehensive WordPress site security including automated backups, malware scanning, and spam protection.

40% OFF Coupon
JETBLACK CopyGet this deal

Related Articles

Fetching coffee...

{}