[wp-trac] [WordPress Trac] #60846: When creating a new template, the Choose a pattern screen doesn't honor the `template_hierarchy` filter

WordPress Trac noreply at wordpress.org
Tue Mar 26 12:49:19 UTC 2024


#60846: When creating a new template, the Choose a pattern screen doesn't honor the
`template_hierarchy` filter
--------------------------+-----------------------------
 Reporter:  aljullu       |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Editor        |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:  template      |
--------------------------+-----------------------------
 Currently, in blocks themes it's possible to use the
 {{{${type}_template_hierarchy}}} filter to alter the template hierarchy.
 However, those filters are not taken into consideration by the `Choose a
 pattern` popup screen that appears when creating a new template in the
 Site Editor, causing a mismatch between the editor and the frontend.

 **Steps to reproduce**

 1. Add this code snippet to your site. You can use the
 [https://wordpress.org/plugins/code-snippets/ Code Snippets plugin]:

 {{{#!php
 <?php
 add_filter( 'page_template_hierarchy', function ( $templates ) {
         return ['single'];
 } );
 }}}

 2. Visit any page in the frontend. You will notice the Single template is
 used, instead of the Page template.
 3. Now, go to Appearance > Editor > Templates > Add New Template > Pages
 and select any page.
 4. Notice in the Choose a pattern screen the suggested content to start
 with is from the Page template, instead of the Single template.

 Expected result: the Site Editor should follow the filter in the same way
 the frontend does. So in step 4 the Single template should appear in the
 Choose a pattern screen, instead of the Page template.

 **Actual result screenshot**

 [[Image(https://github.com/WordPress/gutenberg/assets/3616980/7598c990-1a64-4df3-b509-47d83fc59239)]]

 **Expected result screenshot**

 [[Image(https://github.com/WordPress/gutenberg/assets/3616980/fff09fd9-5600-4969-89f6-dab6523f50de)]]

 **Real life use case**

 In WooCommerce, there are Product Category and Product Tag templates.
 Currently, they fall back to the default WordPress taxonomy templates, but
 we would like them to fall back to a custom WooCommerce template named
 Product Catalog.

 While this would work in the frontend, the experience would be confusing
 in the editor, as creating a Product Category archive template wouldn't
 suggest the same "starting point" from what's seen in the frontend.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60846>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list