Block-based “template parts” in traditional themes

Starting in WordPress 6.1, traditional WordPress themes can adopt the usage of blockBlock Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience.-based template parts in their themes. To enable this feature a theme needs to specify the block-template-parts theme support. The theme developer can add block-based template parts by placing HTMLHTML HyperText Markup Language. The semantic scripting language primarily used for outputting content in web browsers. files containing the block template into the /parts folder inside the root directory of the theme.

function add_block_template_part_support() {
    add_theme_support( 'block-template-parts' );

add_action( 'after_setup_theme', 'add_block_template_part_support' );

These block-based template parts can now be used in the traditional PHPPHP The web scripting language in which WordPress is primarily architected. WordPress requires PHP 5.6.20 or higher templates by using the block_template_part function.


If a theme developer wants to make the site footer editable using blocks, they can create a new file called footer.html inside the my-theme/parts/ directory. This file should contain the default markup of the blocks used to build the footer.

<!-- wp:group {"layout":{"inherit":true}} -->
<div class="wp-block-group">
	<!-- wp:group {"style":{"spacing":{"padding":{"top":"80px","bottom":"30px"}}}} -->
	<div class="wp-block-group" style="padding-top:80px;padding-bottom:30px">
		<!-- wp:paragraph {"align":"center"} -->
		<p class="has-text-align-center">Proudly Powered by <a href="" rel="nofollow">WordPress</a></p>
		<!-- /wp:paragraph -->
	<!-- /wp:group -->
<!-- /wp:group -->

To actually use this template part the theme author then needs to call the block_template_part function and pass the name of the template part as the first and only parameter.

<?php block_template_part( 'footer' ); ?>

Props to @mamaduka, @bph, and @annezazu for reviewing this post.

#6-1, #dev-notes, #dev-notes-6-1