Archived topic
Need some help with date posted and date updated
3 replies · Started by Fem on November 19, 2018
Hi guys,
Ideally, I'd like my timestamp on blogposts to look like this:
posted on [date] by [author], updated on [date]
I checked the documentation and I'm currently displaying only the date updated, as I can't get it to work when I leave out
.posted-on .updated + .entry-date {
display: none;
}
I have tried playing around with inline, inline-block and block, added padding, tried to add content to the date posted, etc. with various results (missing spaces, the dates being mixed up so that it looked as if the publication date was the updated date, etc ;))
At one point, I had something that seemed to work, until I noticed that for some posts, the dates were displaying correctly, i.e., first the date posted, then 'updated on [date]', and for others, it was displayed like this: '[date updated], updated on [date posted]' (so, say '31 October 2018, updated 26 August 2018').
I'm doing something wrong here, but can't figure it out at the moment. Any ideas?
Thanks!
Hi there,
So this is the default display: posted on [date] by [author]
To add the updated after the author, we can do this:
add_filter( 'generate_post_author_output', function( $author ) {
echo $author;
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
printf(
', updated on <time datetime="%1$s" itemprop="dateModified">%2$s</time>',
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
}
} );
Hope this helps :)
Hi Tom,
Works like a charm, many thanks! :)
Cheers, Fem
You're welcome :)