Last-Modified header is removed from server response!

i attached this code to all these hooks (init, template_redirect, wp_footer) to add the Last-Modified header to the server response, i also add some other header for testing. results: the TEST-TEST header was returend to the response BUT not the Last-Modified. i thought it was a conflict with some plugin, that for some reason is unsetting this header. So i moved this code to the footer.php and index.php in the project root. but the result is same.

can anyone explain to me why this is happening? Thank you

try {
    if (get_the_ID()) {
        $LastModified_unix = strtotime(get_the_modified_date('Y-m-d H:i:s')); // с русского на английский
        $LastModified = gmdate(D, d M Y H:i:s \G\M\T, $LastModified_unix);

        $IfModifiedSince = false;
        if (isset($_ENV['HTTP_IF_MODIFIED_SINCE']))
            $IfModifiedSince = strtotime(substr($_ENV['HTTP_IF_MODIFIED_SINCE'], 5));
        if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']))
            $IfModifiedSince = strtotime(substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 5));
        if ($IfModifiedSince  $IfModifiedSince = $LastModified_unix) {
            header($_SERVER['SERVER_PROTOCOL'] . ' 304 Not Modified');
            exit;
        }
        header('Last-Modified: ' . $LastModified);
        header('TEST-TEST: ' . $LastModified);

    }
} catch (Exception $exception) {
}

Topic nginx Wordpress

Category Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.