Skip to content

Instantly share code, notes, and snippets.

@macgraphic
Created May 22, 2023 11:54
Show Gist options
  • Save macgraphic/daf8432cfd2546fe35b8049cd2b3a803 to your computer and use it in GitHub Desktop.
Save macgraphic/daf8432cfd2546fe35b8049cd2b3a803 to your computer and use it in GitHub Desktop.
// By using class, we replace specified text with the formatted date.
add_filter( 'render_block', function( $edited_date, $block ) {
$field_name = 'latestupdate'; // ACF field name
$postId = false;
$format = 'F jS, Y'; // date format
$class = 'displayDateUpdated'; // Additional CSS Class on block to find
$string = 'LastUpdated'; // string of text to replace with date
$date = get_field( $field_name , $postId, $format );
if (
!is_admin()
&& ! empty( $block['attrs']['className'] )
&& $class === $block['attrs']['className']
){
$edited_date = str_replace( $string, $date, $edited_date );
}
return $edited_date;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment