WordPress: Remove query strings from static resources

This is normal code for remove query strings from static resources. Add the code below to your function.php.

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 );

And add this code if you want to exclude some js or css.

function _remove_script_version( $src ){
	$excludes = array(
		'/wp-content/plugins/gd-star-rating/css/gdsr.css?ver=1.9.20',
		'/wp-content/gd-star-rating/css/rating.css?ver=1.9.20'
	);
	$result = $src;
	if ( ! in_array($src, $excludes) ) {
		$parts = explode( '?', $src );
		$result = $parts[0];
	}
	return $result;
}

 

Artikel terkait:   Show Total Weight in Woocommerce

Isi Komentar

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

This site uses Akismet to reduce spam. Learn how your comment data is processed.