Skip to main content

benecaster_get_template_part()

Template Free
benecaster_get_template_part( string $template, array $vars = [], bool $echo = true ): string

Renders one of Benecaster’s template parts, resolving it through your child theme, then your parent theme, then any directory an add-on registered with benecaster_register_template_directory(), then the plugin’s own copy. This is how you build a page out of Benecaster’s pieces without copying its markup — you get whatever the current theme has overridden, which is the behaviour a podcaster expects when they have customised something.

A theme still wins over everything, add-ons included. An add-on directory sits third, so it can replace a built-in default but can never outrank an override a site owner wrote by hand.

Pair it with benecaster_locate_template() when you need to know whether a theme has actually overridden a part, and benecaster_get_template_path() when you need the file that would be loaded.

Parameters

Name Type Default Required Description
$template string — Yes Relative path to the part, without a file extension — 'episode/title', 'account/feed-url'.
$vars array [] No Key–value pairs made available as local variables inside the template. A part that expects $show_id gets it from [ 'show_id' => 12 ].
$echo bool true No Print the result, or return it as a string. Return it when you are composing markup; print it when the part is the output.

Return Value

Type: string

The rendered HTML when $echo is false, and an empty string when it is true. A template that does not exist produces no output and no error, so a missing part fails quietly rather than breaking the page around it.

Example

// Reuse Benecaster's own feed-URL part inside a custom account page.
benecaster_get_template_part( 'account/feed-url', [ 'show_id' => $show_id ] );

// Or capture it and place it yourself.
$markup = benecaster_get_template_part( 'account/feed-url', [ 'show_id' => $show_id ], false );

Need this built rather than just documented? See our services →