Skip to content

Instantly share code, notes, and snippets.

@frikishaan
Created October 11, 2023 12:00
Show Gist options
  • Save frikishaan/81368242eec3bf25ce7f73f5a2262654 to your computer and use it in GitHub Desktop.
Save frikishaan/81368242eec3bf25ce7f73f5a2262654 to your computer and use it in GitHub Desktop.
Custom Date Format for meta value - Generate Press
<?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