
GTmetrixなどで自サイトを調べたとき、下記のように修正項目が提示されることがあります。
■CSSやJavaScriptのURLに関する文言:Remove query strings from static resources
詳細を見ると、
Resources with a “?” in the URL are not cached by some proxy caching servers. Remove the query string and encode the parameters into the URL for the following resources:
と推奨されています。
サーバーによっては、適切にキャッシュされないので、URLを適切な形にしなさいとのことです。
そこで、次の文を functions.php ファイルに加えます。
/*
* Remove Query strings from Static Resources.
*/
function remove_query_string( $src ){
$parts = explode( '?ver', $src );
return $parts[0];
}
if ( !is_admin() ) {
add_filter( 'script_loader_src', 'remove_query_string', 15, 1 );
add_filter( 'style_loader_src', 'remove_query_string', 15, 1 );
}
参考サイト:http://stackoverflow.com/questions/38288476/remove-query-strings-from-static-resources-wordpress
もしくは、プラグインを入れてもOKです。
Remove Query Strings From Static Resources – WordPress plugin | WordPress.org
Remove query strings from static resourc…
wordpress.org