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".
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 ); }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
5.9.0 | Introduced. |