block_template_part() WordPress Function

The block_template_part() function is a versatile way to include template parts in your WordPress content. It can be used to include a template part in your post content, in a sidebar, or in any other location on your site. This function makes it easy to reuse common template parts, such as a header or footer, across your site. You can also use it to include different template parts based on the context in which it is being used. For example, you could use a different header template part on your home page than you do on your post pages. This function can be used with any WordPress theme. All you need to do is create a template part file with the appropriate code for the location where you want to include it. Then, you can use the block_template_part() function to include the template part in your content.

block_template_part( string $part ) #

Print a template-part.


Parameters

$part

(string)(Required)The template-part to print. Use "header" or "footer".


Top ↑

Source

File: wp-includes/block-template-utils.php

function block_template_part( $part ) {
	$template_part = get_block_template( get_stylesheet() . '//' . $part, 'wp_template_part' );
	if ( ! $template_part || empty( $template_part->content ) ) {
		return;
	}
	echo do_blocks( $template_part->content );
}


Top ↑

Changelog

Changelog
VersionDescription
5.9.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.