wordpress的首页,一般都不会缓存,即使clouflare配置了缓存策略。可以进行强制缓存,通过修改主题functions文件配合cloudflare缓存规则实现。我使用的是astra主题。

修改主题文件

 编辑astra主题的functions.php,加入下面内容

1
2
3
4
5
6
function allow_home_cache() {
if (is_front_page()) {
header("Cache-Control: public, max-age=432000, s-maxage=432000, ");
}
}
add_action('send_headers', 'allow_home_cache');

设置cloudflare缓存规则

缓存->Cache rules中,新建缓存规则,编辑表达式

(http.request.full_uri wildcard "https://your.domain/")