Skip to content

Instantly share code, notes, and snippets.

@adamdoe
Last active April 30, 2020 05:29
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 adamdoe/04fda64ffa60d7dee9997c6296c453ea to your computer and use it in GitHub Desktop.
Save adamdoe/04fda64ffa60d7dee9997c6296c453ea to your computer and use it in GitHub Desktop.
WordPress - Check modified time after published time #wordpress
function add_last_updated()
{
$post_time = strtotime(get_post_time('m.d.Y'));
$mod_time = strtotime(get_post_modified_time('m.d.Y'));
$mod_date = get_the_modified_time('m.d.Y');
$date = get_the_date('m.d.Y');
$display_date = ($post_time < $mod_time ? $mod_date : $date);
if ($post_time != $mod_time)
{
echo '<div class="posted-on">Last updated : ' . $display_date . '</div>';
}
}
add_action( 'last_updated', 'add_last_updated' );
@adamdoe
Copy link
Author

adamdoe commented Aug 23, 2016

Use <?php do_action('last_updated'); ?> in template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment