Feedback on ACF date fields

Just want to share my real life experience with date fields and GenerateBlocks Pro on a multilingual site.

On our site we have a list of webinars. To make life easier for the editors it is a custom post type with some custom fields, such as the date. How do I go about implementing this with GP and GB?

The Query Loop
I added Headline blocks with dynamic data mapped to my custom field. There are some quirks though.

If you choose inline width (say I want to embed a custom field in the middle of a sentence), the block will render with display: inline-block and have some whitespace betwee tags. This is usually fine but say you want to surround your custom field with parentheses. Ex: Word (custom_field) word. This is not possible, you will get excess white space ( custom_field ).

Then comes formatting. GB will render ACF date fields according to its storage format (yyyyMMdd), not the display format. Which I like, kind of. I want the date format in my settings to be the default. That is also translatable with WPML. To get this format I had to build a custom plugin, that parses out dates from block content with regex and replaces them formatted. Yuk!

Singular template
Here I could use headline blocks. Problem is, I want my custom fields in a paragraph. While the Headline blocks itself can be a paragraph, I don’t want every word in a sentence to be its own paragraph. Unfortunatley the Container block can’t be a paragraph either so I cannot use that with headlines inside.

Again, custom plugin, with custom short codes, for use within a core paragraph block. Not pretty in a block based world, but it works.

Our website for reference: Insights – Ways

My plugin for formatting dates in Headline blocks and shortcode:

<?php 
/*
Plugin Name: Ways Format date
*/

function ways_format_date( $date, $format ) {
	$timestamp = $date;
	
	if ( ! is_int( $timestamp ) ) {
		$timestamp = strtotime( $date );
	}
	
	if ( ! $timestamp ) {
		return false;
	}

	if ( ! $format ) {
		$format = get_option( 'date_format' );
	}

	return date_i18n( $format, $timestamp );
}

add_filter( 'render_block', function ( $block_content, $block, $instance ) {
    foreach( $block['attrs']['htmlAttributes'] as $htmlAttribute) {
		switch( $htmlAttribute['attribute'] ) {
			case 'data-date-format':
				preg_match_all( '/\b[0-9]{8}\b/', $block_content, $matches );
				
				foreach ( $matches as $match ) {
					$date = ways_format_date( $match[1], $htmlAttribute['value'] );
					
					if ( ! $date ) {
						continue;
					}
					
					$block_content = str_replace( $match[1], $date, $block_content );
				}
				
				break;
		}
	}
	
    return $block_content;
}, 10, 3);

add_shortcode( 'acf_date', function ( $attrs ) {
	extract( shortcode_atts( array(
		'field'			=> '',
		'post_id'		=> false,
		'format_value'	=> true,
		'date_format' 	=> ''
	), $attrs ) );
	
	$acf_date = get_field( $field, $post_id, $format_value );
	
	$date = ways_format_date( $acf_date, $date_format );
	
	if ( ! $date ) {
		return $acf_date;
	}
	
	return $date;
} );