Create a gist now

Instantly share code, notes, and snippets.

anonymous /Display-last-Update-Date.php Secret
Created Jun 29, 2017

What would you like to do?
How to Display the Last Updated Date of Your Posts in WordPress
<?php //* mind this opening php tag
/**
* How to Display the Last Updated Date of Your Posts in WordPress
*/
function wpb_last_updated_date( $content ) {
$u_time = get_the_time('U');
$u_modified_time = get_the_modified_time('U');
if ($u_modified_time >= $u_time + 86400) {
$updated_date = get_the_modified_time('F jS, Y');
$updated_time = get_the_modified_time('h:i a');
$custom_content .= '<p class="last-updated">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';
}
$custom_content .= $content;
return $custom_content;
}
add_filter( 'the_content', 'wpb_last_updated_date' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment