How to Remove Query Strings from Static Resources on WordPress Sites

Google has a great tool to analyze and optimize  the speed of your website called PageSpeed insights. One of the recommendations is to “Remove Query Strings from Static Resources“. Those may be in JavaScript and CSS files. In WordPress many scripts and stylesheets include a query string to identify the version. This can cause problems with caching and will lead to increased load times. In your child-themes function.php file add the following code before the closing sign (?>):

 

 
function hide_wp_version($src) {
global $wp_version;
return str_replace("?ver=$wp_version", '', $src);
}
add_filter('script_loader_src', 'hide_wp_version');
add_filter('style_loader_src', 'hide_wp_version');

 

After you’ve done that check your site on PageSpeed insights again to make sure you had no typos. I also attached a screenshot of my functions.php:

remove query strings from static resources

 
 
 
[ois skin=”subscribe 2″]

April 7th, 2013|Tags: , |
This website uses cookies and third party services. Ok