Remove query strings from static resources on WordPress

Remove query strings from static resources on WordPress

Remove query strings from static resources on WordPressSince page loading speed becoming more and more important for extending your google page rank,caching your blog pages on wordpress is a must and should be taken very seriously. But before you can cache content on your WordPress blog you need to prepare files to get cached successfully.

One part you could do and i describe here is caching your css and js files which you should deliver always staticly. But the main problem of caching these links is the version tag at the end of each file link, cache mechanism won’t just recognize it as cachable content. To prevent loading static content like css and js files dynamicly we have to get rid with the version tag “?ver=x.xx” by Remove query strings from static resources on WordPress Links.
In this short tutorial i will describe a possible solution for wordpress and show you how to do this automaticly by strip off these version tags out of your links to get a better result in caching.

I hope you already have created a child-theme out of your primary theme template. This should be preferred because changes you apply to your files won’t get overwritten on next Theme update.

All we are going to do now is extending your functions.php with a specific replace code.

So open your functions.php with your preferred file editor and add the following code at the end of the file:

// remove version query string by
function _remove_query_string( $src ){
        $parts = explode( '?ver=', $src );
        return $parts[0];
add_filter( 'script_loader_src', '_remove_query_string', 15, 1 );
add_filter( 'style_loader_src', '_remove_query_string', 15, 1 );

After applying this codeset, wordpress is replaces each occuring “?ver=” tag automaticly.

Have Fun with it!

Rating: 5.0/5. From 1 vote.
Please wait...


Jules is the owner and author of ISPIRE.ME. He's a Linux System Engineer, Tech fanatic and an Open Source fan.

You may also like...

2 Responses

  1. Chris Chris says:

    Well done sir Jules… if you have minute to offer feedback on our plugin that allows for custom query string removal that would be super appreciated… positive or negative? Anyway thanks if possible!

    No votes yet.
    Please wait...
    • Jules Jules says:

      Nowdays i wouldnt recommend remove query strings from static resources anymore. GTMetrix e.g. should revise their complaints about it.
      Its more important to have a cache busting feature for .js and .css files by appending query strings than serving outdated static files to clients due long persistent user caches which can lead into malformed page renderings

      Rating: 5.0/5. From 1 vote.
      Please wait...

Leave a Reply

Your email address will not be published. Required fields are marked *

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

Translate »