Remove WP/Theme version in file URL

function remove_theme_version_strings( $src ) {
	
	global $wp_version; // WordPress version
    $theme_version = wp_get_theme(get_template())->get( 'Version' ); // theme version
	parse_str( parse_url($src, PHP_URL_QUERY), $query );
	if ( !empty( $query['ver'] ) && $query['ver'] === $theme_version ) { // I'm just checking for the active theme's version here
		$src = remove_query_arg( 'ver', $src );
	}
	return $src;
	
}

add_filter( 'script_loader_src', 'remove_theme_version_strings' );
add_filter( 'style_loader_src', 'remove_theme_version_strings' );

Share this Post

Leave a Reply

Your email address will not be published. Required fields are marked *