Archived topic
Add the words 'last updated:' before the updated date (updated date filter)
5 replies · Started by Michael on January 6, 2023
Hello,
I have used the following filter to display only the 'last updated date,'
add_filter( 'generate_post_date_show_updated_only', '__return_true' );
However, I'd just like it to say Last updated: before the date. I looked at some support topics and saw some similar-ish topics, but it was about adding and editing different bits of codes together & I'm very much a novice, thus worried about crashing my site by editing!
Is there a code I can use to replace add_filter( 'generate_post_date_show_updated_only', '__return_true' ); that has the 'last updated:' text built into it?
Thank you!
Hi there,
you would need a separate snippet to add the label:
add_filter( 'generate_post_date_output','tu_add_to_post_date' );
function tu_add_to_post_date( $output ) {
return '<span class=”date-label”>Last updated: </span> ' . $output;
}
Hi David,
Thank you for the quick reply.
Do I just add this as a separate snippet and kept the current one as is?
Thats correct you need both, and you can add them together as a single snippet, heres that combined code with some comments for future reference:
// show updated data only
add_filter( 'generate_post_date_show_updated_only', '__return_true' );
// add Last updated label to date
add_filter( 'generate_post_date_output','tu_add_to_post_date' );
function tu_add_to_post_date( $output ) {
return '<span class=”date-label”>Last updated: </span> ' . $output;
}
Perfect - thank you!
You're welcome