themehookalliance icon indicating copy to clipboard operation
themehookalliance copied to clipboard

Add Template Part Filters

Open alexmansfield opened this issue 11 years ago • 2 comments

Any thoughts on adding filters to the arguments of get_template_part() to allow template parts to be selectively overridden? For example:

get_template_part( apply_filters( 'tha_template_part_slug', 'content' ), apply_filters( 'tha_template_part_name', get_post_format() ) );

This should allow child themes (and potentially plugins?) to specify exactly which template parts should be loaded under different circumstances.

alexmansfield avatar Aug 30 '13 12:08 alexmansfield

I'd recommend you check how bbPress does it. Specifically see bbp_locate_template (http://bbpress.trac.wordpress.org/browser/trunk/includes/core/template-functions.php#L61) and bbp_get_template_stack (http://bbpress.trac.wordpress.org/browser/trunk/includes/core/template-functions.php#L167)

MZAWeb avatar Aug 30 '13 14:08 MZAWeb

I'm not sure I fully understand exactly what bbPress is doing, so I could easily be wrong. However, it seems that what bbPress is doing overrides template files loaded by WordPress (for example: index.php), not template parts loaded by the get_template_part() function (for example: content-quote.php). Is that correct?

alexmansfield avatar Aug 30 '13 14:08 alexmansfield