Archived topic
Show Updated Date
3 replies · Started by Shangxiao on August 7, 2022
Hi Admin,
My site uses the Dispatch in the GeneratePress Site Library, this theme default show Publish date on the post, and I want to change it to Updated date,
could you help with this?
(I've found some methods in your forum, but they didn't work in Dispatch theme)
Thanks
Hi Shangxiao,
Dispatch uses a Block Element called Single Post Hero. Open this element through Appearance > Elements. Then, select the Headline Block for the date. Open the dynamic settings, and set the date type to Updated date.
Hi Fernando,
It works, thanks.
But if the post hasn't been updated, the date will be null, and my needs is:
if the post has been updated, show the updated date, if the post hasn't been updated, show the publish date but not nothing.
Thanks
I see. Try adding my-date to the class list of the Headline Block. Then, grab the dynamic data through the block settings as such: https://share.getcloudapp.com/BluGlooL
Then, add this snippet:
add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){
if ( ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'my-date' ) !== false ) {
if( empty ($content) ){
$post_date = sprintf(
'<time class="entry-date published" datetime="%1$s">%2$s</time>',
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date( '' ) )
);
return $post_date;
}
}
return $content;
}, 10, 3);
Adding PHP reference: https://docs.generatepress.com/article/adding-php/#code-snippets