如何禁用 WordPress 缓存

追格官方小助手/ 2023年02月28日/ WordPress/ 浏览 1240

禁用网页缓存功能,需要在 head 标签内,添加相应的内容。在 WordPress 中可以这样做:


function hook_nocache() {
    ?>
  <meta http-equiv="cache-control" content="max-age=0" />
  <meta http-equiv="cache-control" content="no-cache" />
  <meta http-equiv="expires" content="0" />
  <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
  <meta http-equiv="pragma" content="no-cache" />
    <?php
}
add_action('wp_head', 'hook_nocache');


上面的例子,使用 wp_head 向页面头部添加了禁用缓存的内容。


发表评论

暂无评论,抢个沙发...

客服 工单