Archived topic
Posted Date and Updated Date
11 replies · Started by Matt on January 9, 2019
I know this question has been asked before, but I just can't figure out the best way to do it. If someone could take a look at my site and tell me what to do I'd really appreciate it.
I'd like to have the date appear as follows:
Posted Date: XXXXXX Updated Date: XXXXXX
I added my URL for the admins to see.
Thanks for the help!
Hi there,
Add this PHP snippet:
add_filter( 'generate_post_date_output', function( $output ) {
$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 = $time_string . '<time class="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() )
);
echo sprintf( '<span class="posted-on">%1$s</span>', // WPCS: XSS ok, sanitization ok.
sprintf( '<a href="%1$s" title="%2$s" rel="bookmark">%3$s</a>',
esc_url( get_permalink() ),
esc_attr( get_the_time() ),
$time_string
)
);
} );
Adding PHP: https://docs.generatepress.com/article/adding-php/
And this CSS snippet:
.posted-on .updated {
display: block;
}
.posted-on .updated + .entry-date {
display: none;
}
.posted-on .updated:before {
content: " Updated Date: ";
}
.posted-on .published:before {
content: "Posted Date: ";
}
Adding CSS: https://docs.generatepress.com/article/adding-css/
We are working on better methods to make this easier :)
Thanks, I add the PHP and CSS, but it doesn't look right.
Can you please take a look at one of my blog post pages - there are some spaces missing.
Also, I would prefer to have the Last Updated date appear a line below the Posted date.
I also would like everything to appear below the featured image I think :)
Thanks for the help.
Updated the CSS above.
Still doesn't look right:
I'm still seeing the old CSS being added.
Have you tried clearing your caching plugin?
Yes, even cleared Cloudflare.
I'm still seeing the old CSS being added in the source:
https://www.screencast.com/t/f9mQhpnT
Looks like it's added in Additional CSS in the customizer.
Opps, forgot to delete what was there when I moved it over to the Simple CSS plugin :)
Almost done.
I would prefer to not display the date on tag or category pages:
https://www.yardcare.life/tag/buying-guide/
I think it looks funny.
You can either use this filter:
https://docs.generatepress.com/article/option_generate_blog_settings/#options-%E2%80%98date%E2%80%99
Or this CSS:
.tag .posted-on, .tag .updated,
.category .posted-on, .category .updated {
display: none;
}
Got it, thank you!
No problem :)