Remove query strings from static resources on Wordpress

Remove query strings from static resources on WordPress

Remove query strings from static resources on WordPress

Remove query strings from static resources on WordPress
Since 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 http://ispire.me
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!

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

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.