开发者

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

开发者 https://www.devze.com 2023-03-05 19:13 出处:网络
The site doesn\'t send Last-Modified header in its response. I know I should insert somewhere something like header(\"Last-Modified: \" . the_modified_date()); bu开发者_如何转开发t where?The \"Last M

The site doesn't send Last-Modified header in its response.

I know I should insert somewhere something like header("Last-Modified: " . the_modified_date()); bu开发者_如何转开发t where?


The "Last Modified" WordPress plugin works for me. http://wordpress.org/extend/plugins/header-last-modified/

It requires a change in wp-includes/template-loader.php so be careful when updating the WordPress core.


This worked for me on all posts - added into theme functions.php file:

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 insert it at end of file before ?>

0

精彩评论

暂无评论...
验证码 换一张
取 消