- This topic has 9 replies, 3 voices, and was last updated 3 years, 11 months ago by David.
-
AuthorPosts
-
September 2, 2019 at 12:49 am #998868Matthew
Found this CSS
.posted-on .updated { display: inline-block; } .posted-on .updated:before { content: "Last Updated: " } .posted-on .published:before { content: " | Published on: " }
Adds an updated date to a post which is great:
Last Updated: September 2, 2019 | Published on: September 2, 2019
But it would be better if the part:
Last Updated: September 2, 2019
would only appear once the post has actually been revised. Currently it is shown for posts that have only been published but not had any additional revisions made. For those, I would like to have displayed:
Published on: September 2, 2019
thanks,
September 2, 2019 at 6:40 am #999063DavidStaffCustomer SupportHi there,
try this PHP Filter snippet:
add_filter( 'generate_post_date_output', function( $output, $time_string ) { $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on: %2$s</time>'; if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) { $time_string = '<time class="entry-date published" datetime="%1$s" itemprop="datePublished">Published on: %2$s</time> <time class="entry-date updated-date" datetime="%3$s" itemprop="dateModified">| Last Updated: %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() ) ); printf( '<span class="posted-on">%s</span> ', // WPCS: XSS ok, sanitization ok. $time_string ); }, 10, 2 );
September 23, 2019 at 2:44 am #1016409Matthewhi David,
Before the snippet inserted I have:
Last Updated: September 2, 2019 | Published on: September 2, 2019
With the snippet inserted have:
| Published on: Published on: September 2, 2019 | Last Updated: September 2, 2019
I kept the css as is so far, but suspect I should remove the part:
.posted-on .published:before { content: " | Published on: " }
The post I’m testing on has been published and has no revisions. Any further ideas?
thanks,
September 23, 2019 at 3:33 am #1016456DavidStaffCustomer SupportHmmm – not seen this before but it looks like when a post is published WP is generating the UpdatedDate +1 minute.
In this line:
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
Try changing the two instances of
'U'
to'd-m-h'
This will compare the Day / Month / Hour – it does mean that updates after to be older then an hour for it to display, which isn’t a bad thing.
September 23, 2019 at 5:16 am #1016536MatthewRuns like a clock now David
September 23, 2019 at 5:17 am #1016538DavidStaffCustomer SupportGlad to be of help.
September 23, 2019 at 8:30 am #1016819MatthewHey just tested it again with a post that is saved as a draft first.
In a different example test post I’ve had floating around a while as a draft and never published, the published date being used by snippet is the initial first Save of the draft. And the updated date is the actual real first publish date I just made:
Published on: March 20, 2019 | Last Updated: September 23, 2019
Can the snippet revised to disregard draft events do you reckon. I usually will save posts as a draft while I muck around composing them.
thanks,
September 23, 2019 at 8:54 am #1016834DavidStaffCustomer SupportAre you using Gutenberg ?
If so what happens if you use the Publish: Immediately?April 30, 2020 at 1:52 am #1262527YoeriHello!
I’m currently working with these snippets and something isn’t going right:
I use the snippet above on a website for a few months now. It displays ‘Last update: november 26, 2019 by Pieter’
But.. I’m now implenting it in a new website and I have the following:
‘april 29, 2020 Last update: april 29, 2020 by Dennis’
What am I missing here why it shows different?
Thank you guys! 🙂
April 30, 2020 at 4:48 am #1262786DavidStaffCustomer SupportHi there,
i think WP is being a pain in regards to how it captures date/times on new posts.
Try the code provided here: -
AuthorPosts
- You must be logged in to reply to this topic.