Black Friday Sale! Get up to $40 off GP Premium!Learn more

[Resolved] displaying last updated date & time on posts

Home Forums Support displaying last updated date & time on posts

  • This topic has 7 replies, 2 voices, and was last updated 5 months ago by David.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #434161
    Dale

    Hi there.

    On posts that I have updated after initially posting them, I want to display a “last updated” date in addition to the posting date. Initially I added this PHP via Code Snippets plugin, but it added the “last updated” text to pages as well as posts:

    function wpb_last_updated_date( $content ) {
    $u_time = get_the_time('U'); 
    $u_modified_time = get_the_modified_time('U'); 
    if ($u_modified_time >= $u_time + 86400) { 
    $updated_date = get_the_modified_time('F jS, Y');
    $updated_time = get_the_modified_time('h:i a'); 
    $custom_content .= '<p class="last-updated">Last updated on '. $updated_date . ' at '. $updated_time .'</p>';  
    } 
     
        $custom_content .= $content;
        return $custom_content;
    }
    add_filter( 'the_content', 'wpb_last_updated_date' );

    Wp Beginner, at http://www.wpbeginner.com/wp-tutorials/display-the-last-updated-date-of-your-posts-in-wordpress/, suggests adding something like this to the theme, but obviouly it would need to be in a child theme and I’m not sure where to put it (or if it’s correctly formatted for GP):

    $u_time = get_the_time('U'); 
    $u_modified_time = get_the_modified_time('U'); 
    if ($u_modified_time >= $u_time + 86400) { 
    echo "<p>Last modified on "; 
    the_modified_time('F jS, Y'); 
    echo " at "; 
    the_modified_time(); 
    echo "</p> "; } 

    Thoughts? Thanks!

    GP Premium 1.5.5
    #434328
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try adding this CSS:

    .posted-on .updated {
        display: inline-block;
    }
    
    .posted-on .updated:before {
        content: "Last updated: ";
    }
    #434573
    Dale

    sorry, I’m not following. do you mean to use the CSS without any PHP, or to use it with one of the coding options I mentioned above?

    #434596
    Leo
    Staff
    Customer Support

    Just that CSS above should do.

    Have you given it a shot and not working?

    #434790
    Dale

    Yes, I gave it a shot and didn’t see any change. But I had Cloudflare on, so that might have been the issue. I just tried again (with CloudFlare in developer mode) and it worked!

    Thanks! An easier solution than I expected 🙂

    #435124
    Tom
    Lead Developer
    Lead Developer
    #1338086
    Emma

    Hi there, I’ve tried adding this CSS and whilst it works, it’s pushed hard up against the published date so it looks bad. Is there any way to just show the last updated date? When I try to remove the published date (display post date) it removes the Last Updated date too.
    Thanks

    #1338748
    David
    Staff
    Customer Support

    Hi there,

    if you want to just display the Latest date then you would better off using the PHP Snippet here:

    https://docs.generatepress.com/article/generate_post_date_output/#only-show-updated-date

    If you need any more help with it, raise a new topic where you can share a link to your site and we can assist.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.