Governance: Hiding Specific Blocks from the Inserter
A fresh WordPress install comes with over 90 core blocks (Verse, Tag Cloud, Archives, Latest Comments, etc.). For a client site, giving them access to every single block often leads to broken layouts and design inconsistency.
Unlike styles and presets which are handled in theme.json, block visibility is currently handled via PHP filters in functions.php.
1. The Strategy: Allow Lists vs. Block Lists
You generally have two approaches:
- Allow List (Whitelist): "Only show these 10 specific blocks. Hide everything else." (Best for strict governance).
- Deny List (Blacklist): "Show everything except the Verse and Tag Cloud blocks."
2. The Filter: allowed_block_types_all
Add this logic to your theme's functions.php.
Scenario A: The Strict Allow List (Recommended)
This gives you total control. If a plugin adds a block, it won't appear unless you manually add it here.
function my_theme_allowed_block_types( $allowed_block_types, $editor_context ) {
// 1. If we are in the Site Editor (editing templates), allow everything.
// We don't want to lock ourselves out of building the site.
if ( ! empty( $editor_context->post ) ) {
return $allowed_block_types;
}
// 2. Define the strict list for Pages/Posts
return array(
// Text
'core/paragraph',
'core/heading',
'core/list',
'core/list-item',
'core/quote',
// Media
'core/image',
'core/cover',
'core/video',
// Design
'core/group',
'core/columns',
'core/column',
'core/buttons',
'core/button',
'core/separator',
'core/spacer',
// Theme Specific (ACF Blocks)
'acf/hero',
'acf/testimonial',
);
}
add_filter( 'allowed_block_types_all', 'my_theme_allowed_block_types', 10, 2 );
Scenario B: The Conditional Logic
You can allow different blocks based on the Post Type. For example, allowing "Product" blocks only on a "Portfolio" post type.
function my_post_type_specific_blocks( $allowed_block_types, $editor_context ) {
// Check Post Type
if ( ! empty( $editor_context->post ) && 'portfolio' === $editor_context->post->post_type ) {
return array(
'core/paragraph',
'core/image',
'core/gallery',
'acf/project-details',
);
}
// Return default (all blocks) for other post types
return $allowed_block_types;
}
add_filter( 'allowed_block_types_all', 'my_post_type_specific_blocks', 10, 2 );
3. Disabling the "Block Directory"
WordPress has a feature where if you search for a block you don't have, it suggests installing plugins from the repository. You should disable this for clients to prevent them from installing random plugins.
Add this to functions.php:
remove_action( 'enqueue_block_editor_assets', 'wp_enqueue_editor_block_directory_assets' );