From e87cc6d88a0919da1a3452173d226119e4440886 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Mon, 21 Jun 2021 20:18:17 +0100 Subject: [PATCH] Auto-enable the template editor for themes with theme.json only (#32858) --- lib/init.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/init.php b/lib/init.php index f721b8f773f441..c6a7c66af502f3 100644 --- a/lib/init.php +++ b/lib/init.php @@ -188,4 +188,14 @@ function register_site_icon_url( $response ) { add_filter( 'rest_index', 'register_site_icon_url' ); add_theme_support( 'widgets-block-editor' ); -add_theme_support( 'block-templates' ); + +/** + * Enable the block templates (editor mode) for themes with theme.json. + */ +function gutenberg_enable_block_templates() { + if ( WP_Theme_JSON_Resolver_Gutenberg::theme_has_support() ) { + add_theme_support( 'block-templates' ); + } +} + +add_action( 'setup_theme', 'gutenberg_enable_block_templates' );