Skip to content

Instantly share code, notes, and snippets.

Created June 29, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/eb8974a700aeb16c23da529d4ab7ebf7 to your computer and use it in GitHub Desktop.
Save anonymous/eb8974a700aeb16c23da529d4ab7ebf7 to your computer and use it in GitHub Desktop.
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