Make WordPress Core

Opened 8 years ago

Last modified 18 months ago

#22355 new enhancement

Template stack - Beyond parent/child theme relationships — at Initial Version

Reported by: johnjamesjacoby Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Themes Keywords: has-patch
Focuses: Cc:



Robust plugins (BuddyPress, bbPress, et all) are unable to break out of the parent/child restrictions that WordPress imposes on template output. For these plugins to include their own template parts, elaborate code must be written to hook into several different execution points, requiring an intimate knowledge of the inner workings of WordPress's template loading system.


Create a stack of template locations, and allow WordPress to transverse an array of template locations, following the same STYLESHEETPATH/TEMPLATEPATH order it always has, while also enabling additional paths to be added with a priority.


The attached patch includes two new functions in wp-includes/template.php:

  • register_template_stack()
  • get_template_stack()

Register template stack is a wrapper for the 'template_stack' filter. get_template_stack() is a variation of apply_filters() that returns the array of filtered template locations.

A modifications to wp-settings.php calls register_template_stack(), passing get_stylesheet_directory() and get_template_directory() as callbacks, which initialized the core parent/child relationship.


This allows for plugins to register additional paths in the template loader hierarchy, and enables plugins that may come with their own default template parts the option of registering a fallback template location.

This works with both locate_template() and get_template_part(), and has the added benefit removing duplicate items inside of get_template_stack(), resulting in avoiding an additional file system check should the parent and child themes be the same.

Change History (1)

Note: See TracTickets for help on using tickets.