Make WordPress Core

Opened 3 weeks ago

Last modified 3 weeks ago

#59315 new defect (bug)

Merge consideration of block-templates with classic template hierarchy

Reported by: joemcgill's profile joemcgill Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Themes Keywords: needs-patch
Focuses: performance Cc:


For block themes, WordPress will first attempt to locate the appropriate PHP template in the theme for the request before considering a block template in get_query_template. However, any block template that is found at an equal or higher priority takes precedence over the PHP templates. This means that block themes perform several unnecessary file_exists checks to look for a PHP template, when a block template is the desired result.

Design considerations

To fix this, the logic from locate_block_template that attempts to find an appropriate block template would need to be integrated into the foreach loop in locate_template so that the appropriate block template would be found prior to searching for a PHP template, in get_query_template if current_theme_supports( 'block-templates' ) returns true. Alternatively, the order of those two functions could be reversed so that locate_block_template is called first if the theme supports block templates.


The benefit to this approach is that wasteful file operations would not be called if a more appropriate block template is available, speeding up template rendering. For example, when a block theme responds to a standard single post, locate_template will end up calling file_exists 9 times before even considering whether an appropriate block template exists.

Caveats and risks

While file_exists checks have been shown to have a noticeable performance cost in lab profiling, the results of these calls are often cached internally by PHP (see:, so the performance impact in the field may be negligible.

Additionally, there are backwards compatibility considerations that will need to be accounted for with this implementation, as plugins are already making use of direct calls to locate_template and locate_block_template independently of how they’re used in get_query_template.

Change History (2)

#1 @joemcgill
3 weeks ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

Moving this to Future Release, since we're so close to the 6.4 beta release.

This ticket was mentioned in Slack in #core-performance by joemcgill. View the logs.

3 weeks ago

Note: See TracTickets for help on using tickets.