[wp-trac] [WordPress Trac] #64241: wp_is_block_theme should detect block theme if the contains a theme.json file.

WordPress Trac noreply at wordpress.org
Wed Nov 12 20:06:48 UTC 2025


#64241: wp_is_block_theme should detect block theme if the contains a theme.json
file.
-------------------------------------------------+-------------------------
 Reporter:  ifatwp                               |       Owner:  (none)
     Type:  defect (bug)                         |      Status:  new
 Priority:  normal                               |   Milestone:  Awaiting
                                                 |  Review
Component:  Themes                               |     Version:  trunk
 Severity:  normal                               |  Resolution:
 Keywords:  has-patch needs-user-docs reporter-  |     Focuses:
  feedback dev-feedback                          |
-------------------------------------------------+-------------------------
Changes (by ifatwp):

 * keywords:  has-patch needs-user-docs reporter-feedback => has-patch
     needs-user-docs reporter-feedback dev-feedback


Comment:

 When testing block theme detection, I initially verified that it worked
 correctly in most cases. However, after testing additional themes from the
 WordPress.org theme repository, I noticed that some themes (for example,
 Blocksy
 ) are not detected as block themes by wp_is_block_theme().

 Blocksy includes a theme.json file in its root directory and provides
 several block-related features, yet the function still returns false.
 You can check the theme’s structure and configuration here:

 Theme page: https://wordpress.org/themes/blocksy/

 theme.json:
 https://themes.trac.wordpress.org/browser/blocksy/2.1.20/theme.json?rev=297960

 This suggests that the current detection logic — which only checks for
 /templates/index.html or /block-templates/index.html — might not be
 sufficient to reliably identify all block or hybrid block themes.

 To improve this, we could make the is_block_theme() function more strict
 and extensible by incorporating additional checks such as:

 The presence of a theme.json file in the root directory.

 Whether the theme explicitly declares support for block-templates via
 add_theme_support().

 Using a filter (e.g., is_block_theme) so developers can customize or
 extend detection logic when needed.

 {{{#!php
 /**
          * Returns whether this theme is a block-based theme or not.
          *
          * @since 5.9.0
          *
          * @return bool
          */
         public function is_block_theme(): bool {
                 if ( isset( $this->block_theme ) ) {
                         return $this->block_theme;
                 }

                 $paths_to_index_block_template = array(
                         $this->get_file_path( '/templates/index.html' ),
                         $this->get_file_path( '/block-
 templates/index.html' ),
                 );

                 $this->block_theme = false;

                 foreach ( $paths_to_index_block_template as
 $path_to_index_block_template ) {
                         if ( is_file( $path_to_index_block_template ) &&
 is_readable( $path_to_index_block_template ) ) {
                                 $this->block_theme = true;
                                 break;
                         }
                 }

                  // Additional strict and extendable checks
                  $has_theme_json = is_readable( $this->get_file_path(
 '/theme.json' ) );
                 $supports_block_templates = current_theme_supports(
 'block-templates' );

               $this->block_theme = $this->block_theme || ( $has_theme_json
 && $supports_block_templates );

                // Allow filtering for flexibility
                $this->block_theme = apply_filters( 'is_block_theme',
 $this->block_theme, $this );



                 return $this->block_theme;
         }

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/64241#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list