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".

Imporing widget area

If you’ve switched from a classic theme to a block theme and widgets created in the classic theme, you can import them from Import Widget Area dropdown in the Advanced Settings. Select the widget from dropdown and click Import.

Import Widget Area menu in the sidebar.
Screenshot

Managing template parts and patterns

At the bottom of the patterns screen, there is an option to manage all template parts. From you can create new template parts, or rename, delete and reset customizations made to the template parts.

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. To access this mode, Select the template part and click Edit from the toolbar.

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 after clicking on the three dot menu 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.

Replace Header menu of the Header template parts
Screenshot

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