How to allow core Gutenberg blocks selection only when you are inside a custom inner block

You will need to filter the template for the post type: add_action( ‘init’, ‘setup_template’ ); function setup_template() { $post_object = get_post_type_object( ‘post’ ); $post_object->template = [ [ ‘your/custom/block’ ] ]; $post_object->template_lock = ‘all’; } This will pre-populate the post with a single instance of your custom block and lock it from being changed. By locking … Read more

Gutenberg LinkControl suggestionsQuery not working

However, typing into the search input shows all post types (I want it to just show pages). That’s most likely because your code, as well as the example in the documentation, used the wrong property name — suggestionQuery — which should actually be suggestionsQuery (note the plural “suggestions”). So try using suggestionsQuery? <LinkControl suggestionsQuery={ { … Read more

gutenberg widget outputting paragraph marks

Does anyone have any idea what is causing the extra paragraph marks before and after? The Shortcode block performs wpautop() on the content (in the block) before the shortcode is parsed (see source on GitHub), i.e. wpautop( ‘[show-test]’ ) in your case, which then returns <p>[show-test]</p> and then outputs <p><div>hi there.</div></p> after the shortcode is … Read more

Using pre_get_posts on a specific core/query block

A modified version of the suggestion from @birgire works. Note that this applies to the core/post-template block, not the core/query block. add_filter(‘block_type_metadata_settings’, function ($settings, $metadata) { if ($metadata[‘name’] !== ‘core/post-template’) { return $settings; } if ($settings[‘render_callback’] !== ‘render_block_core_post_template’) { return $settings; } $settings[‘render_callback’] = ‘wpse_render_block_core_post_template’; return $settings; }, 10, 2); function wpse_render_block_core_post_template($attributes, $content, $block) { … Read more