Show modified time if post is actually modified

Loosely what you have should work already. However few things are off.

  1. Calling these function without time format will produce values like 1:36 pm (depending on your site’s settings), which are not exactly comparable.
  2. Post modified time can be less than published in some cases, like scheduled posts.

So I would write it along the lines of:

if ( get_the_modified_time( 'U' ) > get_the_time( 'U' ) ) {
    echo 'Last updated:' . get_the_modified_time();
}

U format stands for a numeric Unix timestamp, which is comparison–friendly.

Leave a Comment