
And the user’s ability to create custom hues and gradients has been removed from the block editor. The simplified color palette we configured has replaced the default setting. Our custom theme.json file worked as expected. Now, we can copy the generated output into a new theme.json file, which we’ll save to the root directory of our theme (we’re using Twenty Nineteen here).
INTRO FLASH THEME WORDPRESS CODE
And, once you have a basic template, it’s possible to edit or add to the file by following the established syntax.Įventually, one can envision a vast array of boilerplates and code generators for developers to use. Creating a Basic theme.json FileĪs its name indicates, the theme.json file is written in JSON. Still, there are plenty of goodies to play with! Let’s explore a basic example.
INTRO FLASH THEME WORDPRESS INSTALL
Thus, you may need to install the official Gutenberg plugin to access certain items. The available settings are expected to grow over time and some are experimental. For example: /wp-content/themes/mytheme/theme.json The file should reside in your theme’s root directory. Prerequisitesīefore we start configuring our theme.json file, there are a few requirements to get out of the way: Normally, customizing block styles within the editor means both the original and edited versions are loaded in.Īs the Handbook states, “…if a theme and a user set the font size for paragraphs, we only enqueue the style coming from the user and not the theme’s.” Fewer lines of CSS mean faster load times. There are also some performance benefits. There’s no need to hack away at your stylesheet and only one file to change. In addition, they can set parameters for how users can manipulate blocks in an easier-to-maintain manner.Īnd now for the “magic” part: WordPress will read the settings in your theme.json file and output the necessary CSS for you.

Developers no longer have to settle for Gutenberg’s out-of-the-box defaults or deal with clunky workarounds. The result is a block editor that is more closely aligned with the theme.

Likewise, you might also remove spacing options from that same block. For instance, if you wanted to provide a unique default font size for the Columns block, you can do so within this file. With theme.json, it’s possible to account for one-off situations where a specific block has different defaults than the others. But it also enables developers to go deeper and manage things on a per-block basis. This allows for setting sitewide defaults for styling colors, fonts, and even the editor itself. In practice, it offers theme developers granular control over how various blocks are styled and what options are available to users in the back end.

Explore All Themes & Plugins Bringing Block Styles and Defaults Under One RoofĪccording to the Block Editor Handbook, the rationale behind theme.json is to provide “a canonical way to define the settings of the block editor”.
