diff --git a/lib/full-site-editing/template-loader.php b/lib/full-site-editing/template-loader.php index e0047b81c21f1c..f90f07c02fff55 100644 --- a/lib/full-site-editing/template-loader.php +++ b/lib/full-site-editing/template-loader.php @@ -65,6 +65,19 @@ function gutenberg_override_query_template( $template, $type, array $templates = global $_wp_current_template_content; $current_template = gutenberg_resolve_template( $type, $templates ); + // Allow falling back to a PHP template if it has a higher priority than the block template. + $current_template_slug = basename( $template, '.php' ); + $current_block_template_slug = is_object( $current_template ) ? $current_template->slug : false; + foreach ( $templates as $template_item ) { + $template_item_slug = gutenberg_strip_php_suffix( $template_item ); + + // Don't override the template if we find a template matching the slug we look for + // and which does not match a block template slug. + if ( $current_template_slug !== $current_block_template_slug && $current_template_slug === $template_item_slug ) { + return $template; + } + } + if ( $current_template ) { $_wp_current_template_content = empty( $current_template->content ) ? __( 'Empty template.', 'gutenberg' ) : $current_template->content;