WordPress – Check if post has update

How can I check whether a post has been updated or not in WordPress?

if (post_has_edit())
    the_modified_time();
else
    the_time();

Is there a function like post_has_edit()?

Related posts

2 comments

  1. From the WordPress docs:

    If the post or page is not yet modified, the modified time is the same as the creation time.

    So you can just use the_modified_time(), and if the post hasn’t been modified, it will return the creation time instead.

    To check whether the post has been modified, check whether the_modified_time() == the_time().

  2. If you need check date for multiple post on same page (for example: archive page, search page or any WP_Query), you can use

    if(get_the_modified_date == get_the_date) :
    
        // Do stuff here
    
    endif;
    

    And remember use != for is not equal 🙂

Comments are closed.