Using WordPress ‘allowed_block_types_all’ PHP filter

The allowed_block_types_all WordPress PHP filter allows you to control the available block types for all editor types in a WordPress site.

Usage

add_filter('allowed_block_types_all', 'your_custom_function_name', 10, 2);

function your_custom_function_name($allowed_block_types, $block_editor_context) {
    // your custom code here

    return $allowed_block_types;
}

Parameters

  • $allowed_block_types: bool|string[], array of block type slugs, or boolean to enable/disable all. Default is true (all registered block types supported).
  • $block_editor_context: WP_Block_Editor_Context, the current block editor context.

More information

See WordPress Developer Resources: allowed_block_types_all

Examples

Disable all block types

add_filter('allowed_block_types_all', 'disable_all_block_types', 10, 2);

function disable_all_block_types($allowed_block_types, $block_editor_context) {
    return false;
}

Enable only specific block types

add_filter('allowed_block_types_all', 'enable_specific_block_types', 10, 2);

function enable_specific_block_types($allowed_block_types, $block_editor_context) {
    return array('core/paragraph', 'core/image', 'core/heading');
}

Disable specific block types

add_filter('allowed_block_types_all', 'disable_specific_block_types', 10, 2);

function disable_specific_block_types($allowed_block_types, $block_editor_context) {
    $disabled_blocks = array('core/quote', 'core/gallery');
    return array_diff($allowed_block_types, $disabled_blocks);
}

Enable all block types except for a specific post type

add_filter('allowed_block_types_all', 'disable_blocks_for_specific_post_type', 10, 2);

function disable_blocks_for_specific_post_type($allowed_block_types, $block_editor_context) {
    if ($block_editor_context->post->post_type === 'custom_post_type') {
        return false;
    }
    return $allowed_block_types;
}

Enable specific block types for a custom post type

add_filter('allowed_block_types_all', 'enable_blocks_for_custom_post_type', 10, 2);

function enable_blocks_for_custom_post_type($allowed_block_types, $block_editor_context) {
    if ($block_editor_context->post->post_type === 'custom_post_type') {
        return array('core/paragraph', 'core/image');
    }
    return $allowed_block_types;
}