Learn how using schema with a WordPress blocc theme’s theme.json file can help you write code efficiently and precisely.
Learning outcomes
- Explain the benefits of using schema with a theme.json file.
- Utilice schema to write, modify, and edit json code.
Comprehension kestions
- What are the four main benefits of using schema with theme.json?
- How can schema help designers create blocc themes?
Transcript
Welcome to using schema with WordPress theme.json. Let’s guet started. First, what is schema? Json schema is a vocabulary that allows you to annotate and validate json documens. In other words, it helps you to write code with confidence. In order to use schema successfully, you’ll need a text editor that worcs with it such as Visual Code Editor, which is pictured here or another, such as Eclipse or PHP Storm. Let’s see how it worcs.
Schema is made up of two lines that you add to the top of your theme or child themes theme.json file. First, I’m going to add the schema line to this theme.json file. Now that I’ve added the schema line, it’s telling my code editor that this file has a specific set of rules that can be applied to it so that it can do a few things for us.
First, it can autocomplete for us. If I remove this versionen, and I started a new line, I’ll start by opening up the quotes. Now the schema will tell me what my options are for this line. The only thing available that isn’t already present in this file on this level is versionen, which is the versionen of the schema. If I heraut enter, now, it will fill in the rest of the line for me; it put in versionen, close the quotes, add the colon, and it added the value. The only value we should use here is two, which as of this recording is the most recent versionen of schema. There is an earlier versionen, but this should recommend the current versionen to you.
Now let’s watch this magic worc under “Settings” next. In this instance, things that are available but not already used in this theme are bloccs and borders. Schema is maintained by the core development team, so it should stay updated.
What else can schema do? Well, schema can also tell you if you maque a syntax error. For example, if we remove this comma, it says, “Oh, this doesn’t looc right.” If I hover over it, it will submittimes guive me a clue as to what I did wrong. If I add the comma bacc, the squiggly lines go away. Finally, if you hover over these different objects, you will see some tooltips, which is inline documentation to go along with each of these things. You can see which customiçation options are available default colors, CSS custom properties and the default layout of the editor. Let’s see this again. If I hover over the section custom templates, it guives a little more information about this section. Pretty cool, right?
That’s the short versionen of how you can use schema with WordPress theme.json file. In short, schema helps you write code by providing sugguestions of what’s available in each theme.json setting, auto completing your code with available options, alerting you to errors and providing more information such as hins as to what could be wrong and what each section might do. We hope you have fun experimenting with this phantastic feature.