Template Editor


Description

The Template Editor lets you design custom templates for your posts and pages using the block editor. To put it differently, it allows block editor users to edit and create templates that a page or post uses. Similar to the Site Editor, this feature allows you to edit and create content using blocks, including various theme blocks. 

Objectives

After completing this lesson, participants will be able to:

  • Distinguish between the Template Editor and Site Editor.
  • Identify the difference between templates provided by your theme and custom templates.
  • Use the Template Editor via the WordPress Block Editor.
  • Use the Template Editor via the Site Editor.
  • Assign a template to a post or page.
  • Clear customizations.
  • Delete a template.

Prerequisite Skills

Participants will get the most from this lesson if they have familiarity with:

Readiness Questions

  • Are you familiar with full site editing?
  • Have you installed a block theme?
  • Do you feel comfortable using templates and template parts?
  • What is the difference between the Site Editor and the Template Editor?

Materials Needed

  • A local install of WordPress.
  • A WordPress.org user account.
  • A block theme.

Notes for the Presenter

  • The Template Editor is used to edit and create templates that a page or post uses, and can override primary templates assigned by the Site Editor.
  • It will be helpful to show how custom templates can be created when using the Template Editor.
  • Template Editing Mode is the feature of full site editing that unlocks the ability to switch between editing the content of an individual post/page and the template that an individual post/page uses. 

Lesson Outline

  • Introduction to the Template Editor and Site Editor
  • Identify the difference between templates provided by your theme and custom templates.
  • Explore two different ways to access the Template Editor.
  • How to clear customizations.
  • How to delete a custom template.

Exercises

  • Create a custom landing page using the Template Editor.
  • Assign a different template to a page or post using the Template Editor.

Assessment

What is the function of the Template Editor?

  1.  The Template Editor allows you to add content to your pages and posts.
  2. The Template Editor lets you edit and assign templates to individual posts or pages.

Answer: 2

You can access the Template Editor in two ways. Select all that apply.

  1. If you are using a block theme, you can access the Template Editor when editing posts or pages via the WordPress Block Editor and also via the Site Editor.
  2. If you are using a classic theme you can open the Customizer and search for the Template Editor there.
  3. If you are using a classic theme that has enabled the Template Editor on the backend, you can access the Template Editor only when editing posts or pages via the WordPress Block Editor.

Answer: 1 and 3

The theme you are using will determine what type of templates are available.

  1. True
  2. False

Answer: 1. True

You can create custom templates via the Site Editor.

  1. True
  2. False

Answer: 2. False

You can assign a custom page template to more than one page or post.

  1. True
  2. False

Answer: 1. True

Additional Resources

Example Lesson

The Template Editor allows you to edit and create templates, using blocks. These templates control the look and feel of the posts, pages, or page types on your site. The Template Editor is only available if your site is using a block theme or a classic theme that has enabled the Template Editor on the backend.

You may be asking, what is the difference between the Site Editor and the Template Editor? The Template Editor lets you edit and assign templates to individual posts or pages. The Site Editor on the other hand lets you create site-wide templates for your site. For example, you could use the Site Editor to edit a template for all your pages, but you will still have the ability to override this by assigning a new custom template you created using the Template Editor.  

About Templates

WordPress uses templates to create the layout and structure for posts, pages, or specific page types on your site page. There are a few base templates that are generated when you select a theme. For example:

  • The Home template is used to display the site’s home page if your site is set up to display the latest posts on the home page.
  • The Index template is used to display the index page of all the blog posts.
  • The Page template is used to display the site’s pages if no specific templates are assigned to the page.
  • Many block themes offer other built-in templates like the Single Post template to customize the layout of single blog posts, the 404 template to customize the layout of the 404 error page, the Search template to customize the layout of the search results page, and the Archive template for categories/archives page, etc.

In addition, your block theme may come bundled with custom templates.

In the Template Editor, you can find all the templates on your site, including any custom templates you created and the ones that came bundled with your theme. You can edit these templates and create custom layouts using blocks.

What you need, to use the Template Editor

To work with the Template Editor, you will need a block theme with WordPress 5.9 or later on your site or a classic theme that has enabled the Template Editor in the backend.

A block theme is a theme that uses blocks for all parts of a site, including navigation menus, header, content, and site footer.  All blocks that are available in the WordPress Block Editor can be used in the Template Editor. A set of blocks called Theme blocks are specifically built for the Site Editor and Template Editor.

You can find block themes in the WordPress theme directory by selecting Full Site Editing in the feature filter:

How to find a block theme.
How to find a block theme

Two ways to access the Template Editor

There are two different ways you can access the Template Editor depending on what type of theme you are using:

  • If you are using a block theme, you can access the Template Editor when editing posts or pages via the WordPress Block Editor and also via the Site Editor.
  • If you are using a classic theme that has enabled the Template Editor on the backend, you can access the Template Editor only when editing posts or pages via the WordPress Block Editor.

How to use the Template Editor via the WordPress Block Editor

Edit a template in the Template Editor.
Edit a template in the Template Editor

To edit a template

  1. Click Posts > Add New to add a new post or Pages > Add New to add a new page.
  2. This opens the WordPress Block Editor.
  3. Navigate to the Post/Page Settings sidebar tab.
  4. Under the ‘Template’ section, select ‘Edit’.
  5. This opens the Template Editor and takes you to the template editing mode where you can make changes to the selected template. To go back to the WordPress Block Editor and continue making content changes, click the ‘Back’ link at the top left corner.
  6. When you’re done making changes, select ‘Publish’. This will prompt you to save all the changes you made including the template and the post or page.
  7. Click ‘Save to confirm the changes.
  8. When you make changes to a template, the editor updates the blocks on all pages/posts that use the template.

To create a new custom template

Create a custom template in the Template Editor.
Create a custom template in the Template Editor

  1. Click Posts > Add New to add a new post or Pages > Add New to add a new page.
  2. This opens the WordPress Block Editor.
  3. Navigate to the Post/Page Settings sidebar tab.
  4. Under the ‘Template’ section, select ‘New’.

The ‘New’ option is only available if you are using a block theme that lets you create custom templates.

  1. This opens a dialogue box where you can give a name for the custom template you are about to create. Make sure to give it a descriptive name that describes the purpose of the template e.g. “Full Width”.
  2. Click ‘Create’ to open the Template Editor and go to the template editing mode where you can build the custom template using blocks. To go back to the WordPress Block Editor and continue making content changes, click the ‘Back’ link at the top left corner.
  3. When you’re done making changes, select ‘Publish’. This will prompt you to save all the changes you made including the template and the post or page.
  4. Click ‘Save to confirm the changes.

How to use the Template Editor via the Site Editor

To navigate to templates

Navigating between templates and the Dashboard.
Navigating between templates and the Dashboard

Go to Appearance > Editor to open the Site Editor. You will be taken to the template of your home page (based on what you have set in the Reading Settings) and you can start editing this template.

To view the list of templates available for your site and switch between templates:

Click on the WordPress icon (or Site icon if you have set one) to open the Site Editor left navigation.

Click on ‘Templates’ to view the list of templates.

Click on any template name from the list to switch to that template.

To edit a template

Editing Templates in the Site Editor.
Editing Templates in the Site Editor

  • From the Site Editor (Appearance > Editor (beta) ), click on the WordPress icon (or Site icon if you have set one) to open the Site Editor left navigation.
  • Click on ‘Templates’ to view the list of templates on your site, including any you have created and any that come with your theme.
  • Click on any of the templates in the list to edit the template. From here you can customize the layout of the selected template using blocks.
  • When you are done with the template customization, click ‘Save’.

To add a new template

Adding a new template via the Site Editor.
Adding a new template via the Site Editor

The Site Editor displays the limited number of template choices that you can add to your site. Custom templates cannot be created from the Site Editor. For this, you have to use the Template Editor via the WordPress Block Editor.

  • From the Appearance > Editor , click the WordPress icon (or Site icon if you have set one) to open the Site Editor left navigation.
  • Click ‘Templates’ to view the list of templates on the site.
  • Click ‘Add New’ button in the top right corner to show a drop-down menu with a list of all new templates you can add to your site.
    • Front Page – to display the home page of your site if your site is set up to display a regular page for the home page.
    • Author – to display all the posts written by a single author.
    • Category – to display the posts in a category.
    • Date – to display the posts on the specific date.
    • Tag – to display posts based on a tag.
    • Taxonomy – to display posts from a specific taxonomy term.

How to assign a template to a post or page

Assigning a template to a post or page.
Assigning a template to a post or page

  1. From the WordPress Dashboard, open the post or page that you want to assign the template.
  2. This opens the WordPress Block Editor.
  3. Navigate to the Post/Page Settings sidebar tab.
  4. Under the “Template” section, you’ll see a dropdown with a list of the templates available for your site. If you don’t see a dropdown option under ‘Template’ section, it means your site has not templates created and you need to create new templates.
  5. Pick the template you want to assign to the post or page.

Clear customizations to templates in your block theme

Clearing customizations you have made to a template.
Clearing customizations you have made to a template

When changes are made to templates that came bundled with your block theme, you will see the option to clear customizations.

Click the three-dot menu icon to open a drop-down menu and select ‘Clear customizations’. This will reset the template to the default state and you will lose the changes you made to that template.

This option is only available for the templates that you have already customized. If you don’t find this option, it means your template is already in its default state.

An easy way to identify the templates you have customized is to look for the blue dot next to the template icon in the ‘Added by’ column, in the list of templates.

Hovering over the blue template will also show a tooltip that indicates the template has been customized.

How to delete a template

Deleting a template.
Deleting a template

You can only delete the custom templates that you created via the WordPress Block Editor and the new templates you added via the Site Editor.

  • From the Site Editor (Appearance > Editor ), click on the WordPress icon (or Site icon if you have set one) to open the Site Editor left navigation.
  • Click on ‘Templates’ to view the list of templates on your site.
  • Click the three-dot menu icon on any of the custom templates you created via the WordPress Block Editor and the new templates you added via the Site Editor. From the drop-down menu and select ‘Delete’. This will delete the template.

How to know that you’re editing a template

There are three ways to know you’re editing a template rather than your post or page:

  1. The welcome guide introduces you to this feature upon opening the Template Editor for the first time.
  2. A dark frame appears around the template as you’re editing.
  3. The template name is visible in the Top Bar.

Lesson Wrap Up

Tip: 💡 Follow with the Exercises and Assessment outlined above.