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

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()); but where?

Related posts

Leave a Reply

3 comments

  1. 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');
         }
    }