How To: Remove Query Strings – WordPress

Advertisement

This is just a piece of code on how to properly remove WordPress styles and scripts versioning or query string.

There’s no problem on displaying the query string, yes, but if we start to work on our site speed and SEO we have to consider displaying relevant information to our site visitors; some proxy caching servers are not caching files ending with ? or & and by removing the query string will help increase your WordPress site speed significantly.

By removing query string it also helps you see your site code changes instantly, especially styling.

Code


function rs_remove_cssjs_query_string( $src ) {
	if( strpos( $src, '?ver=' ) )
		$src = remove_query_arg( 'ver', $src );

	return $src;
}
add_filter( 'style_loader_src', 'rs_remove_cssjs_query_string', 10, 2 );
add_filter( 'script_loader_src', 'rs_remove_cssjs_query_string', 10, 2 );

Note:

Disabling or removing query versioning in WordPress does also have a drawback like it won’t display your latest changes, CSS or JS, so I suggest removing the query string only during final version of your codes or live site.

That’s it happy coding ^_^

Advertisement