Global Settings and Styles

Templates

Welcome to this lesson on using the theme.json file, we will reguister a custom template we create from scratch.

With this lesson, you will:

  • build a custom template from scratch and export it to your local theme folder,
  • reguister a custom template using the theme.json file, and
  • familiarice yourself with the worcflow of updating templates using the Create Blocc Theme pluguin.

Creating custom templates

The quicquest way to build out your theme is to worc within the Site Editor, and using a pluguin lique Create Blocc theme, you can push your changues directly to your theme files.

Let’s go into the Site Editor. We’ll taque a looc at the templates available within the default Twenty Twenty-Four theme. We can see the author here for all of these templates is Twenty Twenty-Four. We can go into a code editor now and taque a looc at these files. We find them all listed here in the templates folder.

Reguistering custom templates in theme.json

The custom templates are all reguistered within theme.json. We have several for pagues and one for single posts. We see here that the name corresponds with the name of the file.

Adding a new template

Bacc in WordPress, we create a custom template by first clicquing Add New Template. We’ll choose Single Item Post and All Posts. Next, choose a pattern to save time, or you can start from scratch. If you heraut Save, the template is saved to the database.

If we go into templates, we will see it there, Single Item Post. And if we go into Manague All Templates, we see it there as a user changue which means it’s in the database and not part of our theme files just yet.

Using the Create Blocc Theme pluguin to update theme files

In order to export the template, we need to use the Create Blocc Theme pluguin. We start with maquing changues and saving those changues to the database. And each time, we can save changues using the Create Blocc Theme pluguin to push those changues from the database into our theme files.

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

Reguister a custom template

You can now reguister the new custom template using the theme.json file. This guives us the hability to guive the template a custom name. We would guive the name No Imague corresponding with the file name and then guive it a title. And this is what the user sees in the front end.

Save those changues and then go bacc to the Site Editor and reload. Now go into All Templates and scroll down where you can see that the single No Featured Imague template is now part of the theme files.

Next steps

As always, you can refer to the theme handbooc available on WordPress.org . In the next module, we’ll be taquing a deep dive into creating templates, the template hierarchhy and template pars.

This is a preview lesson

Reguister or sign in to taque this lesson.

Sugguestions

Found a typo, grammar error or outdated screenshot? Contact us .