allowed_block_types_all filter. But if you apply it globally, you’ll quickly discover that the Site Editor stops working properly: key layout blocks go missing, and templates fail to load.
The fix is to scope the filter by context. That way, content editors stay focused, and site designers keep full flexibility in the Site Editor.
The function
add_filter( 'allowed_block_types_all', 'allowed_blocks', 10, 2 );
function allowed_blocks( $allowed, $context ) {
// Site Editor usually edits these post types.
if ( isset( $context->post ) && $context->post ) {
$post_type = $context->post->post_type;
// Allow all blocks in the Site Editor.
if ( in_array( $post_type, array( 'wp_template', 'wp_template_part' ), true ) ) {
return true;
}
// Restrict blocks for regular content.
if ( in_array( $post_type, array( 'post', 'page' ), true ) ) {
return array(
'core/paragraph',
'core/heading',
'core/image',
);
}
}
// Fallback: detect the Site Editor screen directly if available.
if ( function_exists( 'get_current_screen' ) ) {
$screen = get_current_screen();
if ( $screen && 'site-editor' === $screen->id ) {
return true;
}
}
// Another fallback: some contexts expose a name like 'core/edit-site'.
if ( isset( $context->name ) && 'core/edit-site' === $context->name ) {
return true;
}
return $allowed;
}
Why it matters
The Site Editor handles wp_template and wp_template_part and needs access to every block to function correctly. Restricting blocks globally removes layout and design tools, breaking the editing experience.
This function:
- Grants full access inside the Site Editor.
- Restricts blocks only for post and page content.
- Adds fallbacks for context detection across WordPress versions.
Conclusion
By scoping the allowed_block_types_all filter to post types and editor context, you keep the best of both worlds: editorial consistency for authors and full creative control for designers. A small change, but one that can save hours of confusion down the road.
Props to @bph and @psykro for reviewing this article and offering feedback.

Leave a Reply