Strip out query strings from urls of Javascript and CSS files

Stripping out query strings from WordPress javascript and CSS files URLs is a good WordPress development practice. Not only It will help you clean your URLs from unnecessary information but it will also help browsers to cache your website’s static files.

The code snippet bellow is pretty simple. It scans all the static files which are enqueued either by your plugins or by your themes. Whenever it finds an instance of ‘?ver=' it removes it from the URL together with its parameters.

Stripping out query strings from your static files won’t harm your WordPress website. It will actually help your website improve Google page speed score and makes your site load even faster.

To use the snippet Just drop it into your functions.php file and you are done.

functions.php
//Strip out query strings from static Javascript and CSS files
function wph_strip_query_strings( $src ) {
  if( strpos( $src, '?ver=' ) )
    $src = remove_query_arg( 'ver', $src );
    return $src;
  }
add_filter( 'style_loader_src', 'wph_strip_query_strings', 10, 2 );
add_filter( 'script_loader_src', 'wph_strip_query_strings', 10, 2 );