WordPress Tutorial

How to Remove Query Strings From JavaScript and CSS in WordPress

Query strings are URLs that contain either ? or &. Static resources (such as JavaScript and CSS) are usually cached by proxies or CDNs. When a developer makes a change, it will not be rendered instantly due to caching effects, which is when query strings come into play. These strings are not cached, thus allowing updates to be rendered immediately. However, it will also increase the loading time of a webpage. Website optimization tools suggest removing query strings from static resources to increase website speed. This is especially useful for a WordPress site, as it will provide it with many benefits.

Removing query strings from static resources will enable caching on proxy servers, thus increasing the overall WordPress site speed. Your CSS and JavaScript will make fewer server requests, thus decreasing the resource usage of your WordPress site. This will also give your WordPress site a SEO boost, as WordPress sites with better optimization generally have a higher rank on Google.

The downside of query string removal in WordPress can be easily overcome by managing your cache, which will be further explained in this WordPress optimization guide.

What you’ll need

Before you begin this guide you’ll need the following:

  • FTP access
  • WordPress Admin Panel access

Step 1 — Analyzing the site

For this step, I would recommend using GTMetrix. After analysing a test WordPress site, here are the results:


Depending on your WordPress theme, website size, and other factors, the amount of CSS and JavaScript files may vary. Each time a visitors enter your website, the browser will make a request to get CSS, JavaScript or other static content. This will generate more requests to your server and will take a bit more time to load. If you are using a Content Delivery Network, browser caching or WordPress cache plugins your files may not be cached resulting in slower file delivery, thus removing query strings will help improve your WordPress site caching and decrease your resource usage at the same time.

Step 2 — Removing query strings in WordPress

There are a few ways to effectively remove query strings from static resources in WordPress.

Option 1 – Removing query strings from static resources (CSS, JavaScript) in WordPress using plugins

The most convenitent plug-in for query string removal in WordPress would be Speed Booster Pack

After implementing Speed Booster Pack to WordPress, navigate to the Settings of the plugin.

remove query strings in WordPress Booster Pack 1

Tick the box Defer parsing of javascript files and press Save Changes

remove query strings in WordPress Booster Pack 2

It is also possible to use plugins such as Remove Query Strings From Static Resources or Query Strings Remover to reach the same goal.

Option 2 – Removing query strings from static resources (CSS, JavaScript) in WordPress via functions.php

IMPORTANT! Make sure to have a backup of functions.php file before making any changes.

Query strings can be removed from WordPress by adding this code at the bottom of your functions.php file located in wp-includes directory:

// Remove query string from static files
function remove_cssjs_ver( $src ) {
if( strpos( $src, '?ver=' ) )
$src = remove_query_arg( 'ver', $src );
return $src;
add_filter( 'style_loader_src', 'remove_cssjs_ver', 10, 2 );
add_filter( 'script_loader_src', 'remove_cssjs_ver', 10, 2 );

In some cases (depending on your WordPress configuration) this code can cause 500 Internal Server Error. In that case, the plug-ins from Step 1 will do the trick.

Countering the downside of query string removal in WordPress

Proper management of WordPress cache will allow you to deliver the latest files to all visitors without causing any issues. If you are using WordPress caching plugins, you will simply need to clear your WordPress cache after making a change. Same goes if you implemented browser caching for your WordPress site, clearing the browser cache will let you see the latest changes. These few tricks will let you counter the small disadvantage that removing query strings from static resources in WordPress may cause.

Step 3 — Testing the changes

For comparison, here are the results of GTMetrix analysis after removing query strings from static resources in WordPress:



In this short guide, we have learned how to increase the performance of your WordPress website by removing query strings from static resources such as JavaScript or CSS.

About the author

Gediminas B.

Gediminas is a passionate content writer and SEO geek at Hostinger. He started his journey at customer support and aims to use his gathered knowledge to create the most epic content the world has ever seen. From WordPress to server management, there's no topic he can't cover! He also likes cats.

1 Comment

Click here to post a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • THanks guys, speed Booster plugin gave me error last time.

    can you review this please: https://wordpress.org/plugins/remove-query-strings-littlebizzy/

    Also, if had settings page that means database query will slow down…

Get Exclusive Content

Join thousands of webmasters who get our free newsletter with tips on how to drive more traffic and revenue to their websites!

Please wait...

Thank you for sign up!