Template Part Block

Go back to the list of Blocks

The Template Part block is an advanced block introduced in WordPress 5.9 that can be used with a block theme or a theme that supports template editing. They often come with your theme and are used to organize and display your site structure. You can only use them while creating and editing templates to manage blocks in areas repeated across the website. For context, this block is best used to create areas like your site header and site footer. When you change blocks inside a template part, the editor updates the blocks on every block template that includes the template part.

In order to add a Template Part block, click on the add block button and select the Template Part block. You can also type “/template part” and hit enter in a new paragraph block to add one quickly. In many cases, you’ll also see options to select types of Template Part blocks, like Header and Footer when searching for this block. You can search for the header or footer in the block inserter to insert the blocks or use the shortcuts “/header” and “/footer”.

Detailed instructions on adding blocks can be found here.

Adding template parts

You can add templates when using the Template Editor or Site Editor to edit templates directly. After adding a template part, you can choose from existing parts or create a new template part:

Template part block provides two buttons: "choose" and "start blank".

Choosing from existing template parts

Selecting the button “Choose” opens a modal where you can search, preview, and select existing parts. These parts will depend on what your theme has provided:

Using the "choose button", existing template parts can be selected.

Creating new template parts

Selecting “Start blank” will prompt you to add a name. It’s best to pick a descriptive name so that it’s easy to find in the future:

When we create a new template part block, we get a field to edit the name and options to create or cancel.
Click on the “start blank” button to place the block and begin customizing.

Creating new template parts from the template part list

If you are using a block theme, you can also create a new template part from the template part list in Administration Screen > Appearance > Editor > Patterns > Template Parts. Click on the Create patterns icon to find Create template part:

Template part list area also provides an option to create template part.
Creating template part from Patterns area

When you select the Create template part, a modal appears where you can add a name and select the area for the template part. You must provide a name in order to create a new template part:

Upon clicking on create template part, a pop up appears with the title "Create a template part".

Managing template parts and patterns

At the bottom of the patters screen, there is an option to manage template parts. This is a new feature for block patterns that can be saved and synced across the site. It renames the existing Reusable block block type to Pattern and adds a source property to distinguish core and user patterns.

At the bottom of template part list, there is a link named "manage all template parts" which opens this list of template parts.

Customizing template parts

After adding or selecting a Template Part block, you can customize in various ways by adding additional blocks within it. To make it easier to find current template parts to edit, it’s recommended that you use one of the following options:

  • Use List View when you’re editing a template to quickly identify the Headers and Footers in your content to edit.
  • Use the template part focus mode described below.

Template part focus mode

To make it easier to focus specifically on editing a single template part, like a Header or Footer, you can use a dedicated mode that only shows an individual template part. There are a few ways to access this mode:

  • Select the template part in the Site editor > Click on the three dot menu > Select “Edit Header” or the respective template part name. 
  • Select the template part in List View > Click on the three dot menu > Select “Edit Header” or the respective template part name. 
  • From the Browsing sidebar > Navigate to Template Parts > Select the template part you want to customize.
  • From the Top Toolbar > Click on the three dot menu under “Areas” next to the template part you want to customize.

Here’s a video demonstrating one of the ways to access this mode:

Replacing one template part with another

If the theme has more than one template part for the same area, you can use the Replace option in the block toolbar to replace the current template part with another. If you don’t see this option, this is because the theme hasn’t provided multiple template parts for the same area.

Image showing the option to replace a current template part.

Advanced Settings

Under Advanced settings, you can rename the template part and select an area: General, header, or footer. The panel also lets you change the HTML element and add CSS class(es) to your block. You can choose between these HTML elements: Div, header, footer, main, section, article, and aside.

Image of advanced options with the template part block.

Changelog

Was this article helpful? How could it be improved?

First published

Last updated