【发布时间】:2011-08-25 18:59:21
【问题描述】:
网站不会在其响应中发送 Last-Modified 标头。
我知道我应该在某处插入类似 header("Last-Modified: " . the_modified_date()); 的内容,但在哪里?
【问题讨论】:
-
在任何输出之前。
标签: php wordpress http-headers last-modified if-modified-since
网站不会在其响应中发送 Last-Modified 标头。
我知道我应该在某处插入类似 header("Last-Modified: " . the_modified_date()); 的内容,但在哪里?
【问题讨论】:
标签: php wordpress http-headers last-modified if-modified-since
“上次修改”WordPress 插件适用于我。 http://wordpress.org/extend/plugins/header-last-modified/
它需要更改 wp-includes/template-loader.php,因此在更新 WordPress 核心时要小心。
【讨论】:
这在所有帖子上都对我有用 - 添加到主题 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');
}
}
【讨论】:
编辑 wp-config.php 在 ?>
之前将其插入文件末尾【讨论】: