如何在Wordpress中插入最后修改的HTTP标头?

问题描述 投票:1回答:3

该站点在其响应中不发送Last-Modified头。

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

php wordpress http-headers last-modified if-modified-since
3个回答
2
投票

“ Last Modified” WordPress插件为我工作。http://wordpress.org/extend/plugins/header-last-modified/

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


0
投票

这在所有帖子上都对我有用-添加到主题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');
     }
}

-2
投票

编辑wp-config.php将其插入文件末尾吗?>

© www.soinside.com 2019 - 2024. All rights reserved.