- This topic has 23 replies, 4 voices, and was last updated 3 years, 11 months ago by Tom.
-
AuthorPosts
-
April 27, 2020 at 6:28 am #1257703Fekry
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?April 27, 2020 at 7:18 am #1257807FekryHi 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!April 27, 2020 at 7:27 am #1257821DavidStaffCustomer SupportCan 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 );
April 27, 2020 at 7:44 am #1257852FekryYes, 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”
April 27, 2020 at 8:19 am #1258055DavidStaffCustomer SupportOK 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;
April 27, 2020 at 8:34 am #1258089FekryThanks 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?April 27, 2020 at 8:48 am #1258121TomLead DeveloperLead DeveloperIn that case, you can just remove this part of the CSS:
.published:before { content: "Published on "; }
April 27, 2020 at 9:05 am #1258166FekryNow it works as I wish.. thanks David, Tom and Leo.
April 27, 2020 at 9:07 am #1258173TomLead DeveloperLead DeveloperGlad we could help! 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.