== Description ==
This plugin adds the ‘Last-Modified’ header to each post and returns the ‘304 Not Modified’ header to the client without a body in the response if he sent the ‘If-Modified-Since’ header and the post has not changed since that date.
add_action(‘wp’, ‘last_if_modified_headers’ );
function last_if_modified_headers() {
global $post;
if(isset($post) && is_singular()){
$LastModified_unix = strtotime($post->post_modified_gmt);
$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);
}
}
https://tools.keycdn.com/curl
if modified since request
If-Modified-Since: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT
If-Modified-Since: Wed, 21 Oct 2015 07:28:00 GMT
Last-Modified: Wed, 21 Oct 2015 07:28:00 GMT
date: Fri, 27 Dec 2024 10:57:11 GMT Updated
27 Dec 2024, 11:25 AM IST
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since
Check Google search console crawls stats for 304 hearder
save bandwidth and crawl budget.
https://en.web-tool.org/check-last-modified/