Skip to content
Docs
Get RestroPress

Filter

rpress_get_template_part

Updated
On this page

Filters the template file names searched for a template part.

Runs in rpress_get_template_part() after the candidate list is built. When a name is given the list starts with slug-name.php, followed by slug.php. The result is passed to rpress_locate_template(), which checks the theme directories first.

Parameters#

ParameterTypeDescription
$templatesarrayCandidate template file names, in order of preference.
$slugstringTemplate slug.
$namestring|nullTemplate name, or null.

Return value#

array. Candidate template file names.

Example#

function my_template_part_candidates( $templates, $slug, $name ) {
	if ( 'list/fooditems' === $slug ) {
		array_unshift( $templates, 'my-' . $slug . '.php' );
	}
	return $templates;
}
add_filter( 'rpress_get_template_part', 'my_template_part_candidates', 10, 3 );

Source#

Applied in:

  • includes/template-functions.php (line 621), in rpress_get_template_part()

See also#

Was this page helpful?