How to set Last-Modified header from inside Loop
-
I’ve been trying to set the Last-Modified header from inside the loop, but I get a “headers already sent” error. I was using the_modified_date() and php’s header() function. I then tried setting the header in my functions.php file like this:
function modify_http_headers($headers) { $headers['Last-Modified'] = date( 'c', the_modified_date() ); return $headers; } add_filter('wp_headers', 'modify_http_headers');
But that doesn’t work because it’s not inside the loop so the_modified_date() doesn’t work. I searched Google for a long time and tried everything I saw. Can anyone help, please!
- The topic ‘How to set Last-Modified header from inside Loop’ is closed to new replies.