0
votes

Recently i am busy developing a custom theme for a customer.

Now I am using WordPress and i want to disable specific Gutenberg blocks; than we don't have to support or style every block.

To hide blocks I use the filter hook "allowed_block_types".

<?php

add_filter( 'allowed_block_types', static function ( $original_blocks ): array {
    // Alter the allowed block types:
    // - Disable some core blocks with custom blocks
    // - Each custom block you develop needs to be listed below

    // https://rudrastyh.com/gutenberg/remove-default-blocks.html
    return [
        // 1. Common blocks category
        'core/heading',
        'core/paragraph',
        'core/list',
        'core/image',
        'core/gallery',
        'core/quote',
        'core/audio',
        'core/file',
        'core/video',
        // 2. Formatting category
        'core/table',
        ...,
        'custom/custom-block',
        'acf/custom-block',
    ];
});

Normally I have this option:

enter image description here

But when i use the hook mentioned above the option to use reusable blocks disappears.

enter image description here

Is there any way to keep reusable blocks while using the filter hook "allowed_block_types"?

1

1 Answers

4
votes

Add core/block to the allowed list to get reusable blocks back:

<?php

add_filter( 'allowed_block_types', static function ( $original_blocks ): array {
    // Alter the allowed block types:
    // - Disable some core blocks with custom blocks
    // - Each custom block you develop needs to be listed below

    // https://rudrastyh.com/gutenberg/remove-default-blocks.html
    return [
        // 1. Common blocks category
        'core/heading',
        'core/paragraph',
        'core/list',
        'core/image',
        'core/gallery',
        'core/quote',
        'core/audio',
        'core/file',
        'core/video',
        // 2. Formatting category
        'core/table',
        ...,
        'custom/custom-block',
        'acf/custom-block',
        'core/block' // add this for reusable blocks
    ];
});