How to remove query string from static resources

Any expert who knows about removing Remove Query Strings From Static Resources plugin? It’s not working.

Also, I have tried to write this code in function.php file of my theme

function _remove_script_version( $src ){
$parts = explode( '?', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

This is also not working for me.

I have also unchecked “Prevent caching of objects after settings change after settings change” in W3 Total Cache, but I’m still getting the same result in GTMetrix.

Can anybody help me? I am using the Twenty Twelve theme. I have also tried the same techniques in other themes.

Below is a screenshot of the message form GTMetrix:
screen shot of problem

3 Answers
3

It looks like you are using JetPack’s Photon which adds query strings to your URLs. According to this thread there is no way to remove them https://wordpress.org/support/topic/how-to-remove-photon-query-string?replies=2

If you want to get rid of the query strings I would suggest deactivating photon, using a CDN which does not add query strings, and using the snippet you mentioned:

function _remove_script_version( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );

Leave a Comment