Remove query strings from static resources on WordPress

This post is also available in: German

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!


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...

Leave a Reply

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

Human Verification: In order to verify that you are a human and not a spam bot, please enter the answer into the following box below based on the instructions contained in the graphic.