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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |