Created
July 7, 2015 03:03
-
-
Save n1zyy/9cde567fb9d7d0404ac2 to your computer and use it in GitHub Desktop.
Variation of if_modified_since WP plugin to updated Last-Modified based on most recent comment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Do Not Change Anything here */ | |
add_action('template_redirect', 'ism_add_last_modified_header'); | |
function ism_add_last_modified_header($headers) { | |
//Check if we are in a single post of any type (archive pages has not modified date) | |
if( is_singular() ) { | |
$post_id = get_queried_object_id(); | |
if( $post_id ) { | |
$comments = get_comments(array( | |
'number' => 1, | |
'orderby' => 'comment_date', | |
'order' => 'desc', | |
'post_id' => $post_id | |
)); | |
$comment_last_mod = date_create_from_format('Y-m-d H:i:s', $comments[0]->comment_date); | |
$c_date = $comments[0]->comment_date; | |
$post_last_mod = date_create_from_format('U', get_the_modified_time("U", $post_id)); | |
$dates = array($comment_last_mod, $post_last_mod); | |
$newer = max(array($comment_last_mod, $post_last_mod)); | |
$date = $newer->format("D, d M Y H:i:s"); | |
header("Last-Modified: $date"); | |
} | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment