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

Modify the core/paragraph block

Very similar to your goal, I recently wanted to add a block-style to all existing blocks. I found that upon loading an editor page, I must wait for the WP editor JS data to populate before adding my styles, and AFAIK, there’s no callback hook for this. So I chose to add a not-so-elegant delay … Read more

gutenberg dynamic block is returning 404

The handle() method is being called by an add_action(‘enqueue_block_editor_assets, [$block, ‘handle’]) method along with all the other blocks. Here lies the problem. The register_block_type is being called too late. Try to call the function inside the init action hook. You can see an example in the shortcode block of the core.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)