Make WordPress Core

Changeset 38385


Ignore:
Timestamp:
08/26/2016 09:02:08 PM (8 years ago)
Author:
johnbillion
Message:

Themes: Make the template hierarchy for a given template type filterable.

This introduces a {$type}_template_hierarchy filter that allows the hierarchy of candidate template filenames for a given template type to be filtered.

This allows the hierarchy to be added to or altered completely without resorting to re-building the hierarchy from scratch within the template_include filter, which is common and prone to conflicts between plugins and prone to getting out of sync with core's hierarchy.

Fixes #14310

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/template.php

    r37518 r38385  
    2727        $templates = array("{$type}.php");
    2828
     29    /**
     30     * Filter the list of template filenames that are searched for when retrieving a template to use.
     31     *
     32     * The last element in the array should always be the fallback template for this query type.
     33     *
     34     * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date',
     35     * 'embed', home', 'front_page', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
     36     *
     37     * @since 4.7.0
     38     *
     39     * @param array $templates A list of template candidates, in descending order of priority.
     40     */
     41    $templates = apply_filters( "{$type}_template_hierarchy", $templates );
     42
    2943    $template = locate_template( $templates );
    3044
     
    3751     *
    3852     * Possible values for `$type` include: 'index', '404', 'archive', 'author', 'category', 'tag', 'taxonomy', 'date',
    39      * 'home', 'front_page', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
     53     * 'embed', home', 'front_page', 'page', 'paged', 'search', 'single', 'singular', and 'attachment'.
    4054     *
    4155     * @since 1.5.0
Note: See TracChangeset for help on using the changeset viewer.