Type something to search...
How to Edit Templates and Template Parts in the WordPress Site Editor?

How to Edit Templates and Template Parts in the WordPress Site Editor?

On a classic WordPress theme, changing the layout of single posts means opening single.php in a code editor, finding the right spot between PHP tags, and uploading the file again. Moving the author box above the featured image, adding a newsletter signup under every post, or building a different layout for one category all require a developer. On a block theme, the same layouts are made of blocks, and you can change them visually in the Site Editor. The catch is that the Site Editor stores your changes in a way that surprises people: edits to a template override the theme's file, a header edit changes every page at once, and a theme update no longer touches templates you have customized.

This article covers how templates and template parts work in a block theme, how to edit existing ones, how to add new templates for specific pages, categories, or posts, how to create custom templates and template parts, where WordPress stores your changes, and how to reset or save them back into the theme. The steps match WordPress 7.1.

Templates, Template Parts, and Patterns

Block themes use three related building blocks. They look similar in the editor, but they behave differently.

ItemWhat it controlsWhere the theme ships itChanges apply to
TemplateThe full layout for a type of page, such as single posts or the 404 pagetemplates/*.htmlEvery page that uses the template
Template partA reusable area inside templates, such as the header or footerparts/*.htmlEvery template that includes the part
PatternA predesigned group of blocks you insert and then editpatterns/*.phpOnly where it is inserted, unless it is synced

A template answers the question "what does this kind of page look like?" A template part answers "what does this shared area look like?" The header is the classic example: it appears in nearly every template, so it lives in one template part that every template references. Edit the header part once, and every template updates.

Patterns are covered separately in what block patterns are and how to create your own. In this article, they matter only because the Site Editor lists template parts under the Patterns section.

How WordPress Chooses a Template

Block themes follow the same template hierarchy as classic themes. The only difference is the file format: templates/single.html instead of single.php. When a visitor opens a URL, WordPress looks for the most specific template first and falls back to more general ones.

RequestTemplates WordPress tries, most specific first
A single blog postsingle-post-{slug}, single-post, single, singular, index
A pageCustom template assigned to the page, page-{slug}, page-{id}, page, singular, index
A category archivecategory-{slug}, category-{id}, category, archive, index
The blog posts pagehome, index
The site's front pagefront-page, then home or page depending on Reading settings, index
A search results pagesearch, index
A missing URL404, index

This matters in the Site Editor. When you "add a template for the Photography category," WordPress creates a category-photography template. Because that slug is more specific than category or archive, it wins for that category only. The difference between page-level and post-level templates is explained in more depth in the difference between a post and a page template in WordPress.

Opening Templates in the Site Editor

The Site Editor is only available when a block theme is active. To open it:

  1. In the WordPress dashboard, go to Appearance → Editor.
  2. The Site Editor opens with a dark sidebar. In WordPress 7.1, the main menu lists Identity, Styles, Pages, Navigation, Patterns, and Templates.
  3. Click Templates to see every template on the site, including those bundled with the theme and any you have created.
  4. Click a template to preview it and read its description. Click the pencil icon, or the preview itself, to start editing.

WordPress 7.1 also keeps the regular admin toolbar visible at the top of every Site Editor screen, so you can jump back to the dashboard without hunting for an exit button. The Back button in the editor's top-left corner returns you to the previous Site Editor screen.

If you are not sure which template a page uses, open the page itself in the block editor. In the Page settings sidebar, the Summary section shows the template name. Click it and choose Edit template to jump straight to that template.

Editing an Existing Template

Suppose you want to add a "Related reading" heading and a Query Loop under every blog post. That change belongs in the Single Posts template.

  1. Go to Appearance → Editor → Templates.
  2. Click Single Posts, then click the pencil icon.
  3. Open List View from the top toolbar. Templates are deeply nested, and List View is far more reliable than clicking on the canvas.
  4. Find the Post Content block in List View, select the block after it, and use the block inserter to add your Heading and Query Loop blocks.
  5. Click Save.

The save panel lists every entity you have changed: the template, any template parts, synced patterns, and navigation menus. You can untick items you do not want to save yet. Read this list before you click Save, because a stray change to the header part would apply to the entire site.

A few rules that make template editing predictable:

  • Do not delete the Post Content block from single post and page templates. Without it, posts and pages render their title and metadata but no body content.
  • Use theme blocks for dynamic data. Post Title, Post Featured Image, Post Date, Post Author, and Post Terms read data from whatever post is being displayed. A regular Heading block containing typed text shows the same text on every post.
  • Edit layout in templates and content in posts. If text should appear only on one post, add it to that post, not the template.

Previewing the Template While Writing

When you edit a post or page, the block editor can show the surrounding template. Click View in the top-right corner and choose Show template. The header, footer, and other template blocks appear dimmed around your content, which helps writers see how a post will actually look without opening the Site Editor.

Adding a New Template

Most block themes ship only the templates they need. You can add more specific ones without code.

  1. Go to Appearance → Editor → Templates.
  2. Click Add Template in the top-right corner.
  3. Choose what the template should apply to. Options include Front Page, Pages, Author Archives, Category Archives, Date Archives, Tag Archives, Single item: Post, and Custom Template. Custom post types and taxonomies registered on your site appear here too.
  4. For archive types, choose between the general template, for example All Categories, or a specific item, for example one category.
  5. WordPress offers to start from an existing pattern or from a blank template. Choose one, design the layout, and click Save.

Templates you have already created disappear from the Add Template list. If you do not see Front Page, check the Templates list, because it likely already exists.

Example: A Different Layout for One Category

A recipe category might need a grid with large images while other categories keep the default list.

  1. Click Add Template → Category Archives.
  2. Choose Category rather than All Categories, then pick the recipe category from the list. Sites with many categories show a search box.
  3. In the new template, select the Query Loop block and switch its layout to a grid in the block toolbar.
  4. Select the Post Template block inside it and set the number of columns.
  5. Make sure the Query Loop's Inherit query from template setting is on, so it shows posts from the current category.
  6. Click Save.

Because WordPress named the template category-recipes, it applies only to that category. Every other category still uses the general category or archive template.

Creating and Assigning Custom Templates

Custom templates are not tied to a URL pattern. They exist so authors can choose them for individual posts or pages: a full-width landing page, a page without a title, or a post with a sidebar.

To create one from the Site Editor:

  1. Go to Templates → Add Template → Custom Template.
  2. Give it a descriptive name, such as "Landing page, no header".
  3. Build the layout and click Save.

To create one while editing a page, open the Page sidebar, click the template name in the Summary section, and click the add template icon in the popup. Name it, click Create, and you are taken into the template editor.

To assign a custom template:

  1. Open the post or page in the block editor.
  2. In the Summary section of the settings sidebar, click the current template name.
  3. Choose your custom template from the list, or use Change template to browse previews.
  4. Update the post.

Assigning a template affects only that post or page. You can rename custom templates you created from the three-dot menu in the Templates list, but you cannot rename WordPress's default templates or templates that ship with the theme.

Limiting Custom Templates to Certain Post Types

Theme developers declare custom templates in theme.json so they get a proper title and appear only for the right post types. Add a customTemplates array at the top level of wp-content/themes/my-theme/theme.json:

{
  "$schema": "https://schemas.wp.org/wp/7.1/theme.json",
  "version": 3,
  "customTemplates": [
    {
      "name": "page-landing",
      "title": "Landing Page",
      "postTypes": ["page"]
    },
    {
      "name": "single-with-sidebar",
      "title": "Post with Sidebar",
      "postTypes": ["post"]
    }
  ]
}

Each name must match a file in the theme's templates folder, so this example needs templates/page-landing.html and templates/single-with-sidebar.html. Without the postTypes key, a custom template is offered for pages only.

Editing Template Parts

Template parts are where most site-wide edits happen: the logo, navigation, footer links, and copyright line.

  1. Go to Appearance → Editor → Patterns.
  2. In the sidebar, open the Template Parts section. Parts are grouped by area, such as Header and Footer.
  3. Click a template part, then click the pencil icon to edit it.
  4. Make your changes and click Save.

You can also edit a template part in place while editing a template. Select the part in List View, then use the Edit button in its toolbar to open it on its own. Editing it inside the template works too, but the save panel will list the template part separately, which is a reminder that the change applies everywhere the part is used.

Template Part Areas

Every template part has an area: Header, Footer, or General (stored as uncategorized). The area controls three things:

  • Where the part is listed in the Patterns screen
  • Which alternatives the editor offers when you select a Template Part block and choose Replace
  • The semantic wrapper element, so a Header part renders inside header and a Footer part inside footer

That third point is easy to miss. If you build a header from scratch as a General part, it will not be wrapped in a header element, which matters for accessibility and screen-reader landmarks. Choose the right area when you create the part.

Creating a New Template Part

You might want a second header, for example a minimal header for landing pages.

  1. In Appearance → Editor → Patterns, click the add (+) button and choose to create a template part.
  2. Name it, for example "Header Minimal", and choose the Header area.
  3. Build the part with blocks and click Save.
  4. Open the template that should use it, select the existing header in List View, and use Replace to swap in the new part.

You can also turn existing blocks into a template part. Select a Group block in any template, open the block's options menu, and choose Create template part. WordPress moves those blocks into a new part and leaves a Template Part block in their place.

Registering Template Parts in a Theme

In a theme's files, parts are plain HTML files in the parts folder, referenced from templates by slug. Here is a minimal single post template:

<!-- wp-content/themes/my-theme/templates/single.html -->
<!-- wp:template-part {"slug":"header","tagName":"header"} /-->

<!-- wp:group {"tagName":"main","layout":{"type":"constrained"}} -->
<main class="wp-block-group">
  <!-- wp:post-title {"level":1} /-->
  <!-- wp:post-featured-image /-->
  <!-- wp:post-content {"layout":{"type":"constrained"}} /-->
  <!-- wp:post-terms {"term":"category"} /-->
</main>
<!-- /wp:group -->

<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->

To give parts a readable title and the correct area, declare them in templateParts at the top level of theme.json:

{
  "$schema": "https://schemas.wp.org/wp/7.1/theme.json",
  "version": 3,
  "templateParts": [
    { "name": "header", "title": "Header", "area": "header" },
    { "name": "header-minimal", "title": "Header Minimal", "area": "header" },
    { "name": "footer", "title": "Footer", "area": "footer" },
    { "name": "sidebar", "title": "Sidebar", "area": "uncategorized" }
  ]
}

Each name must match a file such as parts/header-minimal.html.

Where the Site Editor Stores Your Changes

Understanding storage prevents most of the confusion people have with block themes.

When you save a template or part in the Site Editor, WordPress does not edit the theme's HTML file. It saves a copy in the database:

  • Templates are stored as posts of type wp_template.
  • Template parts are stored as posts of type wp_template_part.
  • Each one is linked to the active theme through the wp_theme taxonomy.

When rendering a page, WordPress checks the database first. If a customized version exists for the active theme, it uses that copy and ignores the file. This has three practical consequences:

  1. Theme updates do not change customized templates. If the theme author improves single.html in an update but you have customized Single Posts, you keep your version. Templates you never touched update normally.
  2. Customizations belong to one theme. Switching themes leaves your customizations in the database, but the new theme does not use them.
  3. Editing the file does nothing once the template is customized. Developers often edit templates/single.html, refresh, and see no change. The database copy is still winning.

You can see customized templates with WP-CLI:

# Terminal
wp post list --post_type=wp_template --fields=ID,post_name,post_status,post_modified
wp post list --post_type=wp_template_part --fields=ID,post_name,post_status,post_modified

Because these are regular posts, they are included in database backups and migrations. Your WordPress backup routine covers them as long as it includes the database.

Resetting a Template to the Theme Default

When a customization goes wrong, or you want the theme's latest version back, reset the template.

From the Templates list:

  1. Go to Appearance → Editor → Templates.
  2. Click the three-dot menu next to the template and choose Reset.

From inside the template:

  1. Open the template in the editor.
  2. Click the three-dot menu at the top of the Template settings sidebar and choose Reset.
  3. Confirm the Reset to default and clear all customizations prompt.

Template parts reset the same way from the Patterns screen. The reset option appears only for templates that have been customized; if you cannot find it, the template is already in its default state.

Custom templates you created yourself have no theme file to fall back to, so they offer Delete instead of Reset.

Before resetting a heavily customized template, check its revisions. Templates and template parts keep revisions like posts do, so you can often restore a version from before the mistake instead of losing all your work.

Saving Site Editor Changes Back to the Theme

Database customizations are fine for a single site. If you build themes, keep them in Git, or deploy across environments, you want the changes in the theme's files.

There are two common ways to do that:

  • Export the theme. In the Site Editor, open the three-dot More Options menu and choose Tools → Export. WordPress downloads a ZIP of the active theme with your customized templates, parts, and styles written into the files.
  • Use the Create Block Theme plugin. It can save Site Editor changes directly into the active theme's folder, and then clear the database copies so the files are the single source of truth.

After saving changes into the files, reset the database customizations so future edits to the files take effect. Otherwise you end up with two copies that drift apart.

If you are working with a parent theme you did not write, keep your file-level changes in a child theme instead, as explained in creating and customizing WordPress child themes. A child theme can override any template or part by including a file with the same name.

Common Problems and Fixes

  • Theme file edits do not show up. The template has a customized database copy. Reset it in the Site Editor, or delete the wp_template post, and the file will be used again.
  • "Template part has been deleted or is unavailable." The Template Part block references a slug that does not exist for the active theme. This happens after switching themes or renaming a file. Select the block and use Replace to choose an existing part, or restore the missing file.
  • A header change appeared on pages it should not. The header part is shared by every template. Create a second header part for the special case and swap it into only the templates that need it.
  • A custom template does not appear in the post sidebar. It is limited to other post types. Add the post type to postTypes in customTemplates, or recreate it from the post editor.
  • A post shows no body content. The Post Content block was removed from the template. Add it back, or reset the template.
  • The new category template is ignored. Check the slug in the Templates list. The template must match the category's current slug, so renaming a category's slug breaks the link.
  • The Site Editor is missing from the Appearance menu. The active theme is a classic theme. Classic themes show only the template editor in the post sidebar, and only if the theme enables it.

WordPress Templates and Template Parts FAQ

A template is the complete layout for a type of page, such as single posts, pages, or category archives. A template part is a reusable section inside templates, such as the header, footer, or a sidebar. Editing a template part changes every template that includes it.

No. Templates you customize in the Site Editor are saved in the database and take priority over the theme's files, so updates leave them alone. The downside is that you also do not receive the theme author's improvements for those templates until you reset them.

Open the template's revisions to restore an earlier version, or use Reset from the three-dot menu to return to the theme's original file. Reset removes all customizations to that template.

Yes. Create a second template part in the Header area, then replace the header in a custom template with the new part. Assign that custom template to the pages that need the alternative header.

Customized templates are stored in the database as wp_template posts and template parts as wp_template_part posts, linked to the active theme. Templates you have never edited are read directly from the theme's templates and parts folders.

Only partly. Classic themes can opt in to the template editor in the post sidebar for creating custom page templates, but the full Site Editor with template parts and global styles requires a block theme.

Conclusion

Templates and template parts give block themes something classic themes never had: a visual way to change the structure of every page type without touching PHP. The Site Editor lets you edit existing templates, add more specific ones for a page, post, or category, create custom templates authors can choose, and manage shared areas like headers and footers as template parts.

The key to using them confidently is understanding where changes live. Site Editor edits are saved in the database for the active theme and override the theme's files, which protects your work from theme updates but also hides file changes until you reset. Use List View for precise edits, read the save panel before saving, keep revisions in mind before resetting, and export your changes or use Create Block Theme when you want the files to be the source of truth.

Here are some useful references for going deeper on templates and template parts:

  1. WordPress Documentation: Template Editor — adding, assigning, renaming, resetting, and deleting templates.
  2. WordPress Documentation: Site Editor — a tour of the Site Editor interface in current WordPress versions.
  3. WordPress Developer Resources: Templates — how block theme templates are structured and loaded.
  4. WordPress Developer Resources: Template Hierarchy — the full order WordPress uses to choose a template.
  5. WordPress.org Plugins: Create Block Theme — saves Site Editor changes back into theme files.
Tags :
Share :

Related Posts

WordPress optimization with specific recommended approach

WordPress optimization with specific recommended approach

Whether you run a high traffic WordPress installation or a small blog on a low cost shared host, you should optimize WordPress and your server to run

Continue Reading
Creating and Customizing WordPress Child Themes

Creating and Customizing WordPress Child Themes

Creating a child theme in WordPress is a best practice for making modifications to a theme. By using a child theme, you can update the parent theme w

Continue Reading
Understanding the Distinction Categories vs. Tags in WordPress

Understanding the Distinction Categories vs. Tags in WordPress

WordPress, a powerful content management system, offers a plethora of features to organize content effectively. Among these features, categories and

Continue Reading