I have been follow a tutorial here: https://rudrastyh.com/gutenberg/remove-default-blocks.html Where it discusses how to remove default Gutenberg blocks like so:
add_filter( 'allowed_block_types', 'misha_allowed_block_types', 10, 2 );
function misha_allowed_block_types( $allowed_blocks, $post ) {
$allowed_blocks = array(
'core/image',
'core/paragraph',
'core/heading',
'core/list'
);
if( $post->post_type === 'page' ) {
$allowed_blocks[] = 'core/shortcode';
}
return $allowed_blocks;
}
So what this is doing is limiting the default Gutenberg blocks to image, paragraph, heading, and list. I then set the page post type to also allow for the shortcode block. So this works fine, but I am now having an issue where it removes the functionality of reusable blocks and I can’t figure out what needs to be added to add that functionality back.
I tried commenting on that article, but the author wasn’t able to think of a solution currently. I was wondering if anyone had any ideas on adding the reusable block functionality back after adding the above code snippet?
2 s
The reusable block is registered with the core/block
name.
I tried to add it to the allowed blocks in the allowed_block_types
filter, here’s an example:
add_filter( 'allowed_block_types', 'wpse324908_allowed_block_types', 10, 2 );
function wpse324908_allowed_block_types( $allowed_blocks, $post ) {
$allowed_blocks = array(
'core/block', // <-- Include to show reusable blocks in the block inserter.
'core/image',
'core/paragraph',
);
return $allowed_blocks;
}
and it showed the reusable blocks within the block inserter, if at least two other blocks were included as well:
Looking at the /wp-includes/js/dist/editor.js
we can e.g. see this check for core/block
regarding including reusable blocks in the block inserter:
var selectors_canIncludeReusableBlockInInserter = function canIncludeReusableBlockInInserter(state, reusableBlock, rootClientId) {
if (!selectors_canInsertBlockTypeUnmemoized(state, 'core/block', rootClientId)) {
return false;
}