如何在 WordPress 中插入上次修改的 HTTP 标头


How to insert Last-Modified HTTP-header in Wordpress?

站点不会在其响应中发送上次修改标头。

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

"Last Modified" WordPress插件对我有用。http://wordpress.org/extend/plugins/header-last-modified/

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

这对我所有帖子都有效 - 添加到主题函数中.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');
     }
}

Edit wp-config.php将其插入文件末尾的 ?>