Created
May 22, 2023 11:54
-
-
Save macgraphic/daf8432cfd2546fe35b8049cd2b3a803 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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