How to Disable Specific Blocks in the WordPress Gutenberg Block Editor

Discover how to turn off or disable specific blocks in the WordPress Gutenberg Block Editor to simplify your editing workflow and ensure that your design remains consistent, especially for client websites. This tutorial will walk you through various techniques to help you accomplish your goals effectively.

  1. Using the Block Manager Settings

    To access this feature, simply go to “Options” and click on “Preferences.” From there, select “Blocks” to enter the Block Manager preference section. 

  2. Disable Specific Blocks using the allowed_block_types_all WordPress Hook

Using the Block Manager Settings

The Block Manager preference is a helpful tool that lets you easily disable specific blocks in the Gutenberg Block Editor. To access this feature, simply go to “Options” and click on “Preferences.” From there, select “Blocks” to enter the Block Manager preference section. This feature allows you to manage which blocks are available in the Gutenberg Block Editor.

Navigate to Gutenberg Block Editor Preferences
Navigate to Gutenberg Block Editor Preferences
WordPress Gutenberg Editor Block Manager
WordPress Gutenberg Editor Block Manager

Disable Specific Blocks using the allowed_block_types_all WordPress Hook

Sometimes, you may need to disable certain blocks entirely to prevent them from being accessed in the block editor. Additionally, you might want to restrict access to a block on specific post types. In these situations, utilizing the allowed_block_types_all hook is the most suitable option. To disable particular blocks using this method, follow the steps outlined below.

<?php
function disable_specific_blocks( $allowed_block_types, $post ) {
// An array of block names to disable
$disabled_blocks = array(
'core/table',
'core/image',
'core/gallery',
);
// Use this condition to disable blocks on certain post types, otherwise you can remove this IF condition
if ( $post->post_type === 'post' ) {
$allowed_block_types = array_diff( $allowed_block_types, $disabled_blocks );
}
return $allowed_block_types;
}
add_filter( 'allowed_block_types_all', 'disable_specific_blocks', 10, 2 );
?>

In conclusion, disabling specific blocks in the WordPress Gutenberg Block Editor can be accomplished using the user-friendly Block Manager preference or code customization with the allowed_block_types_all hook. The Block Manager offers a simple interface for non-technical users to quickly disable blocks, while the code customization provides advanced flexibility and control for developers. By combining these options, you can efficiently streamline the editing experience, enforce design consistency, and create a customized WordPress website that meets your content creation needs.

Leave a Reply

I won’t send you spam. Unsubscribe at any time.

%d bloggers like this: