【问题标题】:How to insert Last-Modified HTTP-header in Wordpress?如何在 Wordpress 中插入 Last-Modified HTTP-header?
【发布时间】:2011-08-25 18:59:21
【问题描述】:

网站不会在其响应中发送 Last-Modified 标头。

我知道我应该在某处插入类似 header("Last-Modified: " . the_modified_date()); 的内容,但在哪里?

【问题讨论】:

标签: php wordpress http-headers last-modified if-modified-since


【解决方案1】:

“上次修改”WordPress 插件适用于我。 http://wordpress.org/extend/plugins/header-last-modified/

它需要更改 wp-includes/template-loader.php,因此在更新 WordPress 核心时要小心。

【讨论】:

    【解决方案2】:

    这在所有帖子上都对我有用 - 添加到主题 functions.php 文件中:

    add_action('template_redirect', 'theme_add_last_modified_header');
    function theme_add_last_modified_header($headers) {
        global $post;
        if(isset($post) && isset($post->post_modified)){
            $post_mod_date=date("D, d M Y H:i:s",strtotime($post->post_modified));
            header('Last-Modified: '.$post_mod_date.' GMT');
         }
    }
    

    【讨论】:

      【解决方案3】:

      编辑 wp-config.php 在 ?>

      之前将其插入文件末尾

      【讨论】:

      • 在配置中插入什么?
      猜你喜欢
      • 1970-01-01
      • 2011-07-16
      • 2011-02-02
      • 1970-01-01
      • 1970-01-01
      • 2010-12-28
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多