Remove Query Strings from WordPress Static Resources

Open the source code of almost any WordPress site and you will see URLs that end with a small question mark and a version number, such as style.css?ver=6.8 or script.js?ver=1.4. Those little additions are called query strings, and for years speed testing tools have flagged them as a problem. PageSpeed Insights used to list them under a warning about static resources, and many site owners still search for a way to remove them today.
This guide shows how to remove query strings from static resources in WordPress without a plugin, using one small code snippet in your theme functions file. You will also learn what query strings actually do, whether removing them still helps in 2026, and the mistakes that can break your site if you strip versions carelessly. The code is short, the change is reversible, and the whole job takes about ten minutes.
What Are Query Strings in WordPress?
A query string is the part of a URL that comes after a question mark. In WordPress it usually carries a version number, written as ?ver= followed by the version of WordPress, the theme, or a plugin. When WordPress loads a stylesheet or a script, it adds that version automatically so browsers know which copy of the file they are loading. If you update a plugin and its script version changes from 1.3 to 1.4, the new URL tells the browser to fetch the fresh file instead of using the old cached copy.
That version number is useful, and it is the reason query strings exist in the first place. The problem is that some older proxy servers and content delivery networks refused to cache any URL that contained a question mark. They treated style.css?ver=6.8 as a dynamic page instead of a static file, so they fetched it from the origin server on every request instead of serving it from cache. That extra work slowed pages down, which is why speed tools started flagging query strings years ago.
Why Does PageSpeed Flag Query Strings?
PageSpeed Insights and similar tools once showed a specific warning that read like this: remove query strings from static resources. The idea was simple. A file without a query string, such as style.css, looks like a plain static file to every cache in the chain, so browsers, proxies, and CDNs can store it and reuse it without asking the server again. A file with ?ver= attached looked different to some of those caches, so it was served fresh more often than it needed to be.
Modern caching has improved a lot since that warning first appeared. Most CDNs and browsers today cache URLs with query strings perfectly well, and Google no longer treats query strings as a separate PageSpeed item in the same way. That does not mean the warning is meaningless. Some older proxies still exist, some hosting setups still behave the old way, and a clean URL is still easier to read when you inspect your page source. The benefit today is smaller than it used to be, but it is real on some setups, and the fix is so small that it is worth doing on a site that is already well optimised.
If your site is slow, query strings are almost certainly not the main cause. Large images, a slow host, too many plugins, and unoptimised database queries matter far more. Fix those first. Our guide to fix a slow WordPress admin dashboard covers the bigger performance wins, and our web hosting guide explains how a good host affects every part of your site speed. Think of removing query strings as a finishing touch, not as a fix for a slow site.
Does Removing Query Strings Actually Speed Up WordPress?
Honestly, the speed gain on most modern sites is small, often too small to measure in a speed test. If your CDN already caches query string URLs correctly, removing ?ver= changes almost nothing about load time. The files are the same size, the number of requests is the same, and the browser still downloads each file once. What changes is only how some intermediate caches treat the URL.
Where the change does help is proxy caching. Some corporate networks, older caching proxies, and a few budget hosts still skip caching for URLs with a question mark. On those setups, every visitor downloads your CSS and JavaScript files fresh, even though the files have not changed. Removing the query string lets those caches store the files properly, so repeat visitors load the page faster. If your audience uses older networks or shared proxies, the improvement can be noticeable.
There is one more benefit that has nothing to do with speed. A URL without a version number hides which version of WordPress and which plugins you run. That is a small security bonus, because automated scanners look for version numbers to find sites running old software. It is the same kind of small, sensible hardening as our guide to disable XML-RPC in WordPress. It helps a little, but it never replaces updates, strong passwords, and backups.
What Should You Do Before You Remove Query Strings?
The method below edits your theme functions file, so prepare properly before you touch any code. A mistake in functions.php can lock you out of the admin area with a white screen, so a backup is not optional. Work on a staging copy first if you can, and use a child theme so a theme update does not wipe out your change.
- Back up the full site, files and database, before you edit any code. See our guide to back up your WordPress database without a plugin.
- Use a child theme, or a code snippets plugin, so your change survives theme updates.
- Run a speed test now and save the result, so you can compare before and after honestly.
- Keep FTP or File Manager access ready, so you can remove the snippet quickly if something goes wrong.
Method 1: How Do You Remove Query Strings with Code?
This is the cleanest method, and it needs no plugin. WordPress provides two filters, one for stylesheets and one for scripts, that let you change the URL before it is printed on the page. The snippet below uses the built in remove_query_arg function to strip the ver parameter from both kinds of files, while leaving the rest of the URL untouched.
function vtg_remove_query_strings( $src ) {
if ( is_admin() ) {
return $src;
}
return remove_query_arg( 'ver', $src );
}
add_filter( 'style_loader_src', 'vtg_remove_query_strings', 15 );
add_filter( 'script_loader_src', 'vtg_remove_query_strings', 15 );
Add this snippet to the functions.php file of your child theme, or add it through a code snippets plugin if you prefer not to edit theme files directly. The is_admin check is important: it keeps version numbers in the admin area, where WordPress relies on them to load the correct dashboard files. Only the front end of the site loses the query strings. Save the file, then clear every cache you have, including your caching plugin, your CDN, and your browser cache, before you test the result.
The remove_query_arg function is part of WordPress core, and the remove_query_arg documentation on developer.wordpress.org explains exactly how it works. The two filters, style_loader_src and script_loader_src, run for every stylesheet and script that WordPress enqueues properly. Files that a plugin prints directly into the page header without using the enqueue system will not pass through these filters, so a few URLs may keep their query strings. That is normal, and it is usually not worth chasing those last few files.
Method 2: What Is the Version in Path Alternative?
Some performance plugins take a different approach: instead of deleting the version, they move it into the file path, turning style.css?ver=1.4 into something like style.1.4.css or a versioned folder path. The browser still sees a new URL when the file changes, so caching still works correctly, but no question mark appears in the URL. This keeps the cache busting benefit of version numbers while satisfying the old rule about clean static URLs.
You do not need to build this yourself. It is a rewrite rule that most optimisation plugins handle for you, and it adds complexity that a small site does not need. For most WordPress sites, Method 1 is enough. Only consider the version in path approach if you run a large site with aggressive proxy caching and you want version based cache busting to keep working exactly as before.
Method 3: Can You Remove Query Strings with a Plugin?
Yes, and if you already use a performance plugin you may not need any code at all. WP Rocket and Perfmatters both include a setting that removes query strings from static resources with one click, and they handle the edge cases for you. If you already pay for one of those plugins, use its built in option instead of adding custom code, because two methods doing the same job can conflict. If you do not already use a performance plugin, do not install one only for this small job. The code snippet in Method 1 does the same thing with no extra plugin to maintain, update, or pay for.
How Do You Test the Change Before and After?
Testing is simple, but you must clear caches first or you will see the old URLs. Open your homepage, right click, and choose View Page Source. Search the source for ?ver= and count how many matches remain. Before the change you will see dozens. After the change, most stylesheet and script URLs should be clean, with only a few leftovers from plugins that print files directly.
Then run PageSpeed Insights on the same page and compare the result with the test you saved before the change. The PageSpeed Insights tool from Google gives you the clearest before and after comparison. Do not expect a big score jump. On most sites the score moves by a point or two, or not at all. A small or zero change is a normal result, and it means your caching was already working well. The real check is the page source: clean URLs mean the snippet is working.
What Mistakes Should You Avoid?
- Stripping versions during active development: while you are building or updating a theme, version numbers force browsers to fetch the newest file. Remove query strings only on a finished site, or you will keep seeing old CSS after every edit.
- Forgetting to clear the cache: your caching plugin and CDN keep serving the old URLs until you clear them. Always purge every cache after adding the snippet.
- Editing the parent theme directly: the next theme update deletes functions.php changes. Use a child theme or a code snippets plugin instead.
- Removing query strings from everything: some URLs need their query string to work, such as Google Fonts or external scripts. The snippet above only touches files WordPress enqueues, so leave external URLs alone.
- Expecting a huge speed boost: this is a small optimisation. If your site is slow, look at images, hosting, and plugins first, as explained in our guide to change the WordPress database prefix without a plugin and our other performance guides.
Frequently Asked Questions
Is it safe to remove query strings from static resources in WordPress?
Yes, it is safe on a finished site, because the snippet only removes the version parameter from stylesheet and script URLs on the front end. Keep a backup before you start, and keep version numbers in the admin area by using the is_admin check in the code above. Remove the snippet at any time to restore the old URLs.
Will removing query strings improve my PageSpeed score?
Usually only a little, or not at all. Modern CDNs and browsers already cache URLs with query strings, so the gain is small. The change helps most on older proxy setups that refuse to cache URLs with a question mark. Treat it as a finishing touch after you fix images, hosting, and heavy plugins.
Do I need a plugin to remove query strings?
No. One small snippet using the style_loader_src and script_loader_src filters does the job, and it is shown in Method 1 above. WP Rocket and Perfmatters also offer the same setting, so use the plugin option if you already own one of those, but do not buy a plugin only for this.
Why do my CSS changes not show after removing query strings?
Because the browser now caches the file by its plain URL, it may keep serving the old copy after you edit the CSS. Clear your browser cache and purge your caching plugin and CDN after every style change. During active development, remove the snippet temporarily so version numbers force fresh files, then add it back when the site is finished.
Last updated: December 2026.



