Created
October 11, 2023 12:00
-
-
Save frikishaan/81368242eec3bf25ce7f73f5a2262654 to your computer and use it in GitHub Desktop.
Custom Date Format for meta value - Generate Press
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
<?php | |
add_filter( 'render_block', function( $block_content, $block ) { | |
$field_name = 'start_date'; // ACF field name | |
$postId = false; | |
$format = 'M j, Y g:i A'; // date format | |
$class = 'format-date'; // Additional CSS Class on block to find | |
$string = 'start_date'; // string of text to replace with date | |
$date = get_field( $field_name ); | |
$formatted_date = date($format, strtotime($date)); | |
if ( | |
!is_admin() | |
&& ! empty( $block['attrs']['className'] ) | |
&& $class === $block['attrs']['className'] | |
){ | |
$block_content = str_replace( $string , $formatted_date , $block_content ); | |
} | |
return $block_content; | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment