Sometimes you have seen Remove Query String from Static Resources during checking website performance on GTMetrix, Pingdom Test Tool, and Google PageSpeed Insights.

In all options to increase website performance, there is one option is to remove query string from static resources.
You can simply do this by using this code snippet in functions.php

<?php
function remove_query_string_from_static_res( $src ) {
if( strpos( $src, '?ver=' ) )
// Remove version from CSS and JS
//query string may be variable for version may be `ver` or `v`
$src = remove_query_arg( array('ver'), $src );
if( strpos( $src, '?v=' ) )
$src = remove_query_arg( array('v'), $src );
return $src;
}
add_filter( 'style_loader_src', 'remove_query_string_from_static_res', 10, 2 );
add_filter( 'script_loader_src', 'remove_query_string_from_static_res', 10, 2 );

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.