Home / Attachments / Remove Query Strings From Static Files
Duplicate Snippet

Embed Snippet on Your Site

Remove Query Strings From Static Files

Use this snippet to remove query string from CSS & JS files and improve performance ratings.

1.6k
Code Preview
php
<?php
function wpcode_snippet_remove_query_strings_split( $src ) {
	$output = preg_split( "/(&ver|\?ver)/", $src );
	return $output ? $output[0] : '';
}
add_action( 'init', function () {
	if ( ! is_admin() ) {
		add_filter( 'script_loader_src', 'wpcode_snippet_remove_query_strings_split', 15 );
		add_filter( 'style_loader_src', 'wpcode_snippet_remove_query_strings_split', 15 );
	}
} );

Comments

Add a Comment