Last active
April 30, 2020 05:29
-
-
Save adamdoe/04fda64ffa60d7dee9997c6296c453ea to your computer and use it in GitHub Desktop.
WordPress - Check modified time after published time #wordpress
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
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' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
<?php do_action('last_updated'); ?>
in template.