Discover in this tutorial how to use the theme.json schema to make it easier for you to configure and customize the file.
WordPress 5.8 introduced the theme.json file which is one of the key pieces on which the block themes or FSE (Full Site Editing) are based.
The good thing is that the theme.json file can be used in classic themes so I invite you to get familiar with it as soon as possible.
That’s why I’m preparing a series of tutorials focused on how it works and how you can modify it to your liking.
In the previous tutorial we went through the whole structure of the theme.json file and you saw that remembering all the settings and properties is not easy.
But I also told you not to worry because there was a trick that would make it easier for you to configure the theme.json file and that is to use its schema.
Once configured some code editors such as Visual Studio Code or WebStorm, can interpret it and offer several advantages such as:
- Provide recommendations of what options are available in each setting
- Autocomplete existing options with the correct syntax
- Warn of errors in the code
- Provide hints on how errors can be fixed
Let’s see how to achieve it
How to use schema with theme.json
If you don’t already have it, create a file called theme.json and place it in the root of your theme.
Whether the file already exists or you just created it, add this line to the beginning of the file:
To see this and another 1097 code snippets of this website, login or subscribe here.
With this simple line you will see how much easier it will be to modify the file from a code editor such as Visual Studio Code, since you will have all the aids mentioned at the beginning.
Conclusions
Activating the schema of the theme.json file is very easy to do and makes it much easier to manage it, so I recommend you to always activate it.
If you have any question, please leave it in the comments. And if you want to give me a suggestion for future snippets, please send it through the contact form.
Benefits of being a subscriber. 🙂