[Resolved] Show last update date on posts and google results

Home Forums Support [Resolved] Show last update date on posts and google results

Home Forums Support Show last update date on posts and google results

  • This topic has 23 replies, 4 voices, and was last updated 2 years ago by Tom.
Viewing 9 posts - 16 through 24 (of 24 total)
  • Author
    Posts
  • #1257703
    Fekry

    Word “updated” still shows in every POST(updated or just published).
    I”ve published a fake post with name “Helli David” and word “updated”shows in it.
    I’ve put a new URL link in the orginal message for the fake post I just published.
    I need word “updated” to show only in the really updated posts.
    What should I do?

    #1257807
    Fekry

    Hi Generatepress team
    I’ve spent many hours with you to know how to (show last update date on posts and google results).
    But word “updated” till shows in every post (updated or just published).
    My site is not ready yet, but I had to disable the coming soon page repeatedly.
    Although, I did not receive the support I wish!

    #1257821
    David
    Staff
    Customer Support

    Can you make sure that this is the only PHP snippet you have added to your site. Please remove any old snippets and add this code:

    add_filter( 'generate_post_date_output', function( $output, $time_string ) {
        $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">%2$s</time>';
    
        $updated_time = get_the_modified_time( 'U' );
        $published_time = get_the_time( 'U' ) + 86400;
    
        if ( $updated_time > $published_time ) {
            $time_string = '<time class="entry-date updated-date" 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 sprintf( '<span class="posted-on">%s</span> ',
            $time_string
        );
    }, 10, 2 );
    #1257852
    Fekry

    Yes, it’s the only PHP snippet.
    And I’ve put this CSS AS Tom recommend:

    .updated-date:before {
    content: “Updated on “;
    }
    .published:before {
    content: “Published on “;
    }

    Now, I’ve modified the post with Title (Hello David) but the word still “published” not “updated”

    #1258055
    David
    Staff
    Customer Support

    OK so that means the code is working 🙂
    It will only show the Updated date IF the update is made more than 24hrs after it was originally published.

    This line of code gets our published date and adds 24hrs ( 86,400 seconds ).

    $published_time = get_the_time( 'U' ) + 86400;

    If you wanted you could change it to 1hr ( 3,600 seconds ) like so:

    $published_time = get_the_time( 'U' ) + 3600;

    #1258089
    Fekry

    Thanks David. It works now.
    Another thing please, I don’t want to show word “published” when a post is not updated.
    How should I do that?

    #1258121
    Tom
    Lead Developer
    Lead Developer

    In that case, you can just remove this part of the CSS:

    .published:before {
        content: "Published on ";
    }
    #1258166
    Fekry

    Now it works as I wish.. thanks David, Tom and Leo.

    #1258173
    Tom
    Lead Developer
    Lead Developer
Viewing 9 posts - 16 through 24 (of 24 total)
  • You must be logged in to reply to this topic.