Skip to content
Advertisement

Display last date a post was updated on WordPress

I’m using some PHP to display the last time a blog post was updated on WordPress using the get_the_time and get_the_modified_time functions. However, I can’t get the last modified time to display inline in the paragraph.

 <?php 
        $x = get_the_time('U');             
        $m = get_the_modified_time('U');    
        if ($m != $x) { 
            $t = the_modified_time('F d, Y');
            echo "<p class="lastupdated">Updated on $t </p>"; 
        } 
    ?>

Here’s a screenshot of the result:

Screenshot

Advertisement

Answer

the_modified_time prints the last modification time, so it prints it before you print your <p>.

Instead you’ll want to use get_the_modified_time for setting $t, like so:

$t = get_the_modified_time('F d, Y');
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement