Disable block from editor based on post type

You can use the allowed_block_types hook:

<?php
function wpse_allowed_block_types($allowed_block_types, $post) {
    // Limit blocks in 'post' post type
    if($post->post_type == 'post') {
        // Return an array containing the allowed block types
        return array(
            'core/paragraph',
            'core/heading'
        );
    }
    // Limit blocks in 'page' post type
    elseif($post->post_type == 'page') {
        return array(
            'core/list'
        );
    }
    // Allow defaults in all other post types
    else {
        return $allowed_block_types;
    }
}
add_filter('allowed_block_types', 'wpse_allowed_block_types', 10, 2);
?>

Tweak with as many or as few conditions as you need. You can also enable non-Core blocks by identifying their namespace and name and putting those in the array.

Leave a Comment