Hi, welcome to this lesson on creating custom templates.
With this lesson, you will build a custom template from scratch and export it to your
local theme folder, register a custom template using the theme.json file, and familiarize
yourself with the workflow of updating templates using the CreateBlock theme plugin.
So let's dive in.
The quickest way to build out your theme is to work within the site editor, and using
a plugin like CreateBlock theme, you can push your changes directly to your theme files.
Let's go into the site editor.
We'll take a look at the templates available within the default 2024 theme.
We can see the author here for all of these templates is 2024.
We can go into a code editor now and take a look at these files.
Here we find them all listed here in the templates folder.
The custom templates are all registered within theme.json.
We have several for pages and one for single posts.
We see here that the name corresponds with the name of the file.
So back in WordPress, we create a custom template by first clicking Add New Template.
We'll choose Single Item Post and All Posts.
Now here we choose a pattern to save time, or you can start from scratch.
Now if I hit Save, this template is saved to the database.
If we go into templates, we see it there, Single Item Post.
And if we go into Manage All Templates, we see it there as a user change.
So that means it's in the database and not part of our theme files just yet.
So in order to export the template, we need to use the Create Block Theme plugin.
So we go in and we can make changes and save those changes.
And each time we can save changes using the Create Block Theme plugin to push those changes
from the database into our theme files.
So if we go into our code editor, we see the custom template, Single-Post.
Now we can rename this if we want to something more descriptive.
I'll put No Image.
And now I want to register using the theme.json file, the new custom template.
Now this gives us the ability to give the template a custom name.
So we would give the name No Image corresponding with the file name and then give it a title.
And this is what the user sees in the front end.
So I save those changes and then I would need to go back to the site editor and reload.
And if I go into All Templates and scroll down, I can see that the single No Featured
Image template is now part of the theme files.
As always, you can refer to the theme handbook available on WordPress.org.
In the next module, we'll be taking a deep dive into creating templates, the template
hierarchy and template parts.