Cyber Monday Sale!

Save up to $50 through December 5th.

Shop Now

[Resolved] Last Updated Date Displaying as Yesterdays Date for All Posts

Home Forums Support [Resolved] Last Updated Date Displaying as Yesterdays Date for All Posts

Home Forums Support Last Updated Date Displaying as Yesterdays Date for All Posts

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #1147618
    Scott

    Hi there

    I’ve followed the instructions in the discussion below, and now have Last Updated dates displaying in my Page Hero under my H1.

    https://generatepress.com/forums/topic/how-to-show-the-last-updated-post-date-when-using-page-header-edit-element/

    My first question relates to the dates themselves. They are all displaying dates from the past 2 days, even if no change has been made to these posts. What triggers the [modified_date] to be updated?

    Second question:

    I’m using the below CSS to change the font size.

    .hero-meta {
    font-size: 18px;
    }

    It is working well for desktop but is too large on mobile. I’ve tried adding the below with no success:


    @media
    (max-width: 768px)

    #1147942
    David
    Staff
    Customer Support
    #1149788
    Scott

    Hi David

    Yes. Here’s what I’ve done:

    Add the below PHP:

    function display_modified_date_shortcode () {
    $mod_date = get_the_modified_date();
    if ( get_the_date() !== $mod_date ) {
    return ‘Last Updated: ‘ . $mod_date;
    }
    }
    add_shortcode( ‘modified_date’, ‘display_modified_date_shortcode’ );

    Added the below under the H1 in my Page Hero Header element:

    [modified_date]

    Added the below CSS to edit the text size:

    .hero-meta {
    font-size: 18px;
    }

    #1149891
    Tom
    Lead Developer
    Lead Developer

    Instead of introducing new code, I would just use the standard {{post_date}}

    Then you can tell that template tag to show the updated date with a filter:

    add_filter( 'generate_page_hero_post_date', function() {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    
        if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
            $time_string = 'Last Updated: <time class="entry-date-updated" datetime="%3$s" itemprop="dateModified">%4$s</time>';
        }
    
        $time_string = sprintf( $time_string,
            esc_attr( get_the_date( 'c' ) ),
            esc_html( get_the_date() ),
            esc_attr( get_the_modified_date( 'c' ) ),
            esc_html( get_the_modified_date() )
        );
    
        return $time_string;
    } );

    Let me know 🙂

    #1150022
    Scott

    Hi Tom

    Thanks for your reply.

    So, I’ve replaced the previous PHP with the code in your message above.

    I’ve then replaced [modified_date] under my H1 with {{post_date}}.

    The result is it now displays “Last Updated:” but with no date.

    Any ideas?

    #1150721
    Tom
    Lead Developer
    Lead Developer

    Hmm, that means the WP core function get_the_modified_date() isn’t doing anything on your site.

    Do you have any other custom functions added?

    #1150805
    Scott

    Nope, this is it as far as I’m aware.

    #1150933
    Tom
    Lead Developer
    Lead Developer

    Are your date and time format configured in “Settings > General”?

    #1150938
    Scott

    Yep. And they were appearing OK when applying the earlier code from David, it’s just the dates didn’t seem correct.

    #1150941
    Tom
    Lead Developer
    Lead Developer
    #1150953
    Scott

    OK, so using the updated code, the date is now displaying under the H1. However, it seems to have the same issue as earlier, where all dates are very recent (last few days), even if the post hasn’t been modified. Would something like the sidebar changing due to a related post widget trigger the modified date? Or does the content of the post itself need to change?

    Also, I’ve enabled post date in archive in Layout > Blog and interestingly this displays the original post date, not the modified date.

    #1151444
    Tom
    Lead Developer
    Lead Developer

    Are you sure the posts haven’t been modified? What’s the latest modified date for them in the Dashboard?

    These are all core WordPress functions, so if they’re malfunctioning it means something on your installation/server is configured wrong.

    #1151620
    Scott

    I can’t find the modified date in the dashboard, only published.

    Regardless, I think they all must have been “modified” by some work I was doing a few days ago with the categories.

    Same issue discussed here: https://wordpress.stackexchange.com/questions/135268/how-to-update-the-modified-time-of-a-post-only-when-content-is-changed

    I’m OK to leave it for now.

    Any tips for changing text size on mobile per my original post?

    #1151729
    Tom
    Lead Developer
    Lead Developer

    Give this a shot:

    @media (max-width: 768px) {
        .hero-meta {
            font-size: 18px;
        }
    }
    #1151781
    Scott

    Hmm yeah that’s what I had tried already. Just tried again with no success.

    So I have this in my Page hero element:

    <br>
    <br>
    <h1>{{post_title}}</h1>
    {{post_date}}

    And this in my Additional CSS:


    @media
    (max-width: 768px) {
    .hero-meta {
    font-size: 8px;
    }
    }

    Does that look right?

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