Hi @syoung68
There is a filter to change the output of the field’s content. You can add the following snippet code into your theme or plugin:
add_filter(
'meta_field_block_get_block_content',
function ( $content, $attributes ) {
$field_name = $attributes['fieldName'] ?? '';
// TODO: input your field name here.
if ( 'YOUR_FIELD_NAME_HERE' === $field_name ) {
return date( 'm/d/Y', strtotime( $content ) );
}
return $content;
},
10,
2
);
I’m going to do a setting allowing to choose the output format of the block soon, but you can use the above code to display your field in the mean time.
Please let me know if it works or not.
If it works for you, please do a quick review for it. Thank you very much.
Phi.
Thank you! Worked like a charm. I did make one change to account for empty fields…
add_filter(
'meta_field_block_get_block_content',
function ( $content, $attributes ) {
$field_name = $attributes['fieldName'] ?? '';
// TODO: input your field name here.
if (( 'YOUR_FIELD_NAME_HERE' === $field_name ) && ($content != '')) {
return date( 'm/d/Y', strtotime( $content ) );
}
return $content;
},
10,
2
);
Glad to hear it worked out. I’ve forgoten to do a empty check. You also can get the date_format from the settings like get_option(‘date_format’) instead of of harded-code ‘m/d/Y’. I think that’s better.