When optimizing WordPress site performance, a common question is how to remove query strings from static resources. Often, your CSS and JavaScript files have version numbers added to their URLs, like domain.com/style.css?ver=4.6. Some servers and proxy servers have trouble caching files with query strings, even when using the cache-control:public header.
By removing query strings, you can sometimes boost your website’s caching efficiency. This approach also resolves the “Remove query strings from static resources” alert you may see in speed test tools like GTMetrix and Pingdom.

Keep in mind that query strings serve an important purpose. WordPress developers use file versioning to address caching concerns. For instance, when a developer updates style.css from ?ver=4.6 to ?ver=4.7, browsers recognize it as a new file, ensuring the updated version is loaded. If you remove query strings and then update a plugin or theme, the old version may linger in cache, which can cause display issues on the front-end until the cache clears or expires.
Additionally, query strings help organize assets in development environments.
Table of Contents
Remove Query Strings from Static Resources
There are a few effective ways to remove query strings: you can use a code snippet or leverage a WordPress plugin. If your website uses a content delivery network (CDN) for asset delivery, this step may not be necessary. Some CDN providers can cache files with query strings, so it’s wise to check with your web host or CDN provider to confirm how their caching works before proceeding.
1. Remove Query Strings from Static Resources with Code
To remove query strings from your files, use a small amount of code. Be sure to create a backup of your site, then set up a child theme and add the following snippet to your child theme’s functions.php file.
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){
$output = preg_split("/(&ver|?ver)/", $src);
return $output[0];
}
add_action('init', 'remove_query_strings');
Important: Modifying your theme’s source code may lead to issues if done incorrectly. If you’re not confident, consult a developer for help. Alternatively, you can use the free Code Snippets plugin, which lets you add code safely and easily without risking site outages.
Just create a new snippet, add the provided code, set it to run only on the site’s front-end, and save. That’s it—the query strings will be removed! Don’t forget to clear your WordPress site cache for the changes to appear on the front-end.

With Query Strings (Before Code)
Here’s how your scripts look when query strings are present.

Without Query Strings (After Code)
This is what scripts look like after query strings are removed.

2. Remove Query String from Static Resources with a Plugin
If you prefer not to edit code, you can use a WordPress performance plugin that includes this functionality. Many plugins provide the ability to remove query strings with minimal setup and can help you implement other site optimizations, working alongside your existing caching solutions.

No More Query Strings
Once you use one of the methods above, warnings about query strings in tools like GTMetrix or Pingdom should no longer appear.

Should You Always Remove Query Strings?
Before proceeding, it’s important to consider whether removing query strings is the best choice for your site. While this can improve caching, especially for browsers, proxies, and content delivery networks that ignore files with query strings, it can also create potential drawbacks:
- Loss of Version Control: As covered earlier, file versioning ensures users see the latest style and script updates. Removing query strings might result in users or visitors viewing outdated files, increasing the risk of broken layouts or scripts due to cached old versions.
- Plugin and Theme Compatibility: Some plugins and themes rely on query strings for functionality beyond caching—such as cache-busting, conditional loading, or in development workflows. Removing query strings globally could impact functionality.
- CDN Compatibility: Many modern CDNs (like Cloudflare and KeyCDN) cache static files even with query strings present. In some cases, they offer configurable settings to control this behavior. Always check your CDN’s documentation—removal may not yield significant improvements depending on your stack.
Best Practices for Optimal Cache Management
If you decide to remove query strings, take additional steps to manage cache effectively and minimize potential issues:
- Implement Cache-Busting Naming Conventions: Instead of relying on query strings, consider renaming versioned files during deployment. For example,
style.css?ver=4.7becomesstyle-v4.7.css. - Update Asset References on Deployment: Automate asset reference updates in your template files or use a build tool (like Gulp or Webpack) to handle filename changes and cache busting.
- Leverage Browser Caching Headers: Adjust your
.htaccessor server configuration to set long cache lifetimes for your CSS and JS files. For Apache, useExpiresorCache-Controlheaders; for Nginx, use theexpiresdirective.
Alternatives: Using a CDN with Advanced Caching
If you’re using a CDN, review its cache settings. Many allow you to specify whether to ignore query strings, cache a file as a unique resource for each string, or only honor specific parameters. For example, Cloudflare’s “Cache Everything” page rule or KeyCDN’s “Ignore Query String” option. Optimizing these settings can solve cache issues without modifying your site’s code or plugins.
Additionally, modern performance plugins and managed hosts often include built-in optimization for query string caching. Always check your hosting or plugin documentation before making code changes.
Testing and Troubleshooting
After removing query strings, use tools like Google PageSpeed Insights, GTMetrix, or Pingdom to verify that the warning has disappeared and your resources are being cached as expected. Always clear your cache (site, server, browser, and CDN) after making these adjustments.
If you notice any issues such as outdated scripts or styles, review your cache settings and consider manually updating file names or cache rules to ensure new assets are always delivered after updates.
Summary
- Removing query strings can help with static asset caching in some environments, but may affect versioning and updates.
- Always weigh the tradeoffs—test thoroughly and use reliable backup solutions before making caching changes.
- Explore if your CDN or hosting platform offers query string controls for static resources before altering your theme files or using plugins.
- Regularly monitor your website’s front-end for issues after removing query strings, especially after plugin or theme updates.
By following these best practices and considering your specific hosting and caching situation, you can implement more robust asset caching that improves site performance without compromising update reliability or development workflows.




