[wp-trac] [WordPress Trac] #13239: Filter locate_template template_names variable
WordPress Trac
noreply at wordpress.org
Tue Oct 11 08:25:27 UTC 2016
#13239: Filter locate_template template_names variable
-------------------------+-----------------------------
Reporter: chrisjean | Owner:
Type: enhancement | Status: reopened
Priority: normal | Milestone: Future Release
Component: Themes | Version: 3.0
Severity: normal | Resolution:
Keywords: has-patch | Focuses:
-------------------------+-----------------------------
Comment (by tifosi):
Alternative patch: 22355.2.patch. Turned locations array into associative.
Manipulation of array in filters by key.
Usage
{{{#!php
<?php
add_filter( 'template_locations', function( $locations ) {
unset( $locations['theme-compat'] );
array_walk( $locations, function ( &$v, $k, $s ) { $v .= $s; },
'/partials' );
return $locations;
}, 10, 1 );
add_filter( 'template_locations', function( $locations ) {
unset( $locations['theme-compat'] );
$new_locat = [
'template-partials' => get_template_directory() . '/partials',
'template-templates' => get_template_directory() . '/templates'
];
return array_merge( $new_locat, $locations );
}, 10, 1 );
add_filter( 'locate_template', function( $location, $template_names ) {
if ( in_array( 'header.php', $template_names ) ) {
$location = ( is_child_theme() ) ? get_stylesheet_directory() .
'/header.php' : get_template_directory() . '/partials/header.php';
}
return $location;
}, 10, 2 );
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/13239#comment:104>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list