Add Published Date & Last Modified Date in WordPress

How to Add Published Date & Last Modified Date in WordPress

in Posts & pages
Google+ LinkedIn

Sometimes on a specific project, you have requirement to also display last modified date of pages and posts along with published date. So here is a code snippet to display both in your WordPress.

Posted on <?php the_time( 'F jS, Y' ); ?>
<?php
    // display last modified date
    $modified_time = get_the_time( 'U' );
    $new_modified_time = get_the_modified_time( 'U' );
    if ( $new_modified_time != $modified_time ) {
        echo " and last modified on ";
        the_modified_time( 'F jS, Y' );
        echo ".";
    }
?>

Share the love

If you like this snippet, share it with others!

Leave a Reply

Your email address will not be published. Required fields are marked *