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’] ) { … Read more

Add classname to Gutenberg block wrapper in the editor?

Actually it can be done with the filter: const { createHigherOrderComponent } = wp.compose; const withCustomClassName = createHigherOrderComponent( ( BlockListBlock ) => { return ( props ) => { if(props.attributes.size) { return <BlockListBlock { …props } className={ “block-” + props.attributes.size } />; } else { return <BlockListBlock {…props} /> } }; }, ‘withClientIdClassName’ ); wp.hooks.addFilter( … Read more

Required (mandatory) Gutenberg block

No fast and easy solution for you. Read discussion here and here. You may try to write some rather sophisticated Gutenberg code to implement this feature, or maybe you could implement some save_post hook to check saved block structure with parse_blocks and do something if they don’t match your required structure. For example, prevent post … Read more

Add PHP block template to content using wp_insert_post

I’ve modified serialize_block a bit: function serialize_block_template( $block ) { $block_content=””; if (isset($block[2])) { $index = 0; foreach ( $block[2] as $chunk ) { $block_content .= is_string( $chunk ) ? $chunk : serialize_block_template( $block[2][ $index++ ] ); } } return get_comment_delimited_block_content( $block[0], $block[1], $block_content ); } Disclaimer: could have some bugs, only tested it for … Read more