Hide or show Gutenberg custom block using date range

Here’s an untested suggestion, to remove an HTML block of type:

<!-- wp:block/timed-block {"dateFrom":"2018-11-14", "dateTo":"2018-12-18"} -->
    <section>
       ...
    </section>
<!-- /wp:block/timed-block -->

from the rendered content, using the render_block filter (available in 5.0+):

add_filter( 'render_block', function( $block_content, $block ) {
    // Remove the block/timed-block from the rendered content.
    if ( 'block/timed-block' === $block['blockName'] ) {
        $block_content="";
    }
    return $block_content;
}, 10, 2 );

One could further handle date constrains with the parsed attributes $block['attr']['dateFrom'] and $block['attr']['dateTo'] as needed.

Hope it helps!

Leave a Comment