wordpress-develop icon indicating copy to clipboard operation
wordpress-develop copied to clipboard

Enhancement: Refactor `locate_template` to support customizable template paths.

Open Luc-cpl opened this issue 1 month ago • 3 comments

This change introduces a new filter to the locate_template() function that allows themes and plugins to participate in the template resolution process by modifying the list of template lookup paths before the lookup occurs.

Currently, locate_template() searches for templates in a fixed set of predefined locations (child theme, parent theme, and theme-compat). While this behavior works well for the default theme hierarchy, it does not provide a mechanism for extending the lookup paths in a controlled and predictable way.

The added filter makes it possible to reuse shared template parts across multiple themes without duplicating files. A common use case is a setup where a site uses a third-party parent theme, multiple client-specific child themes, and a shared default set of template parts maintained by the project. With this change, the lookup order can remain fully predictable (child theme → shared defaults → parent theme → core fallback) while preserving the existing behavior.

This update does not alter the default template hierarchy or behavior. Themes and plugins are unaffected unless they explicitly opt in by using the new filter.

Unit tests are included to verify that template paths can be extended while maintaining backward compatibility.

Trac ticket: https://core.trac.wordpress.org/ticket/64465#ticket


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Luc-cpl avatar Dec 31 '25 20:12 Luc-cpl