Gutenberg Reusable Block of WordPress

This is the way it worked for me: $post = get_post( $post_id ); if ( has_blocks( $post->post_content ) ) { $blocks = parse_blocks( $post->post_content ); foreach ( $blocks as $block ) { if ( isset( $block[‘attrs’][‘id’] ) ) { echo $block[‘attrs’][‘id’]; } elseif ( ‘core/block’ === $block[‘blockName’] ) { $block_content = parse_blocks( get_post( $block[‘attrs’][‘ref’] )->post_content … Read more

Change default colors in paragraph block settings

Rather than adjusting the default palette, you can define (and enforce) a custom palette. <?php // Add a custom palette add_action( ‘after_setup_theme’, ‘wpse_block_color_palette’ ); function wpse_block_color_palette() { add_theme_support( // Define the colors ‘editor-color-palette’, array( // First color – black array( ‘name’ => esc_html__( ‘Black’, ‘textdomain’ ), ‘slug’ => ‘black’, ‘color’ => ‘#2a2a2a’, ), // Second … Read more

Create custom blocks for bootstrap

Rather than create new blocks to represent the Bootstrap classes. You should enqueue the bootstrap js and css files in your theme as you say you normally do. Once bootstrap has been added to the theme, you can simply assign the bootstrap css classes to the already existing Gutenberg blocks. As demonstrated in the following … Read more

Group block without inner wrapper

I did this in the function.php of my theme and it worked like a charm. Note: I am only missing the id, maybe someone can share a solution for that too. function custom_render_block_core_group ( string $block_content, array $block ): string { if ( $block[‘blockName’] === ‘core/group’ && !is_admin() && !wp_is_json_request() ) { $html=””; $tag = … Read more

Is there a better way to implement responsive images than what WordPress uses by default?

Unfortunately, I’ve found the images within Gutenberg/block editor a lot left to be desired and the development work with images in 2020 has been primarily focused on adding cropping, rotating images within the block editor. The limitations of responsive images in the block editor is one of my biggest criticisms of the block editor. What … Read more

Gutenberg default value not saved in json

When I set default values in my attributes for my Gutenberg blocks, the values can be consumed on the client, but it does not appear in the JSON data until I change the attribute with setAttributes. When we register a block type (think of it like a post type) which happens on each page load, … Read more

How can I list all custom post types in a block

wp.data.select(‘core’).getPostTypes() will show return an array of objects that represent each registered post type that is available via the REST API. wp.apiFetch({path:’wp/v2/posts’}).then( res => console.log( res ) ); will retrieve the latest posts. You may want/need to update the parameters to suit your needs. See the docs for more details