Make WordPress Core

Opened 3 years ago

Last modified 5 weeks ago

#22355 new enhancement

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

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

Description (last modified by johnjamesjacoby)


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 this array following the same STYLESHEETPATH/TEMPLATEPATH order it always has, while also enabling additional paths to be added with a priority (similar to the filters API.)


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 modification to wp-settings.php calls register_template_stack() two times, passing get_stylesheet_directory() and get_template_directory() as callbacks, to initialize the core parent/child relationship, ensuring complete backwards compatibility.


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 (8)

#1 @obenland
3 years ago

  • Cc obenland added

#2 @JustinSainton
3 years ago

  • Cc justinsainton@… added

#4 @curtismchale
3 years ago

  • Cc curtis@… added

#5 @mordauk
3 years ago

  • Cc pippin@… added

#6 @MikeSchinkel
3 years ago

  • Cc mike@… added

#7 @johnjamesjacoby
3 years ago

  • Description modified (diff)
Note: See TracTickets for help on using tickets.