Classic and block(-based) themes both use the same template hierarchy, so for example in classic themes, we can add a template named single-<post type>.php
which would be used as the default template for displaying single posts in a specific post type, and in block themes, the equivalent template is named single-<post type>.html
, but that template must be placed in the templates
directory (e.g. at wp-content/themes/your-theme/templates
) as opposed to the theme’s root directory in classic themes.
So you should rename your template to single-foobar.html
and WordPress will automatically load it on single post pages in the foobar
post type, e.g. at https://example.com/foobar/foo-1/
.
However, to make it appear as the “Default template”, e.g. in the “Post tab → Template panel” in the block editor’s sidebar, you need to register the template as a default template using the default_template_types
hook:
add_filter( 'default_template_types', 'my_theme_default_template_types' );
function my_theme_default_template_types( $template_types ) {
$template_types['single-foobar'] = array(
'title' => 'Single Foobar',
'description' => 'Displays a single foobar post.',
);
return $template_types;
}
Preview (WordPress v6.0.1):
So I hope that helps and you should check the Differences and similarities between classic themes and block themes, and you might also want to learn about registering custom templates: (which in classic themes, they use a header line, i.e. a PHP comment like Template Name: Foobar
)