{"id":376820,"date":"2023-01-31T07:52:01","date_gmt":"2023-01-31T15:52:01","guid":{"rendered":"https:\/\/css-tricks.com\/?page_id=376820"},"modified":"2023-03-01T07:01:49","modified_gmt":"2023-03-01T15:01:49","slug":"defining-global-settings","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/defining-global-settings\/","title":{"rendered":"Defining Global Settings"},"content":{"rendered":"\n
So far, we\u2019ve spent time getting familiar with We are going to build on that knowledge in this article.<\/p>\n\n\n\n\n\n\n\n We discussed how JSON has a structured syntax. We can see that in the basic outline of the Each object in the basic outline is a \u201ctop level\u201d of the file. You can think of the objects as sections where various things are configured. Disregarding the We\u2019re spending most of our time in the Again, this is where we configure WordPress features, sort of like the Why is this relevant to a theme\u2019s global styles? Several WordPress features affect styling, like UI controls for padding, margins, colors, and fonts. Without enabling those, there\u2019s no way to apply these and other styles in the Global Styles UI in the Site Editor.<\/p>\n\n\n\n In short: what we define here is what WordPress uses to add theme support for the Site Editor\u2019s global style settings that are used throughout the theme.<\/p>\n\n\n The WordPress Block Editor Handbook<\/a> provides a table that outlines available features we can enable in the For example, you were using The equivalent in As you might imagine, there are nested features within these features. For example, if we were adding support for As of WordPress 6.1, these are the There are ongoing discussions<\/a> to add the theme.json<\/code>, the foundation for all WordPress block themes. We covered the various JSON data types and common terminology related to working with the JSON syntax.<\/p>\n\n\n\n
WordPress Block Theme CSS and Style Settings Guide<\/h4>\n\n\n
\n
theme.json<\/code><\/a><\/li>\n\n\n\n
\n
Table of contents<\/h3>\n <\/summary>\n \n
\n<\/li>
\n\n\nWhat we mean by \u201ctop level\u201d<\/h3>\n\n\n
theme.json<\/code> file:<\/p>\n\n\n\n
{\n \"version\": 2,\n \"settings\": {},\n \"styles\": {},\n \"customTemplates\": {},\n \"templateParts\": {}\n}<\/code><\/pre>\n\n\n\n
version<\/code>, there are four top-level sections:<\/p>\n\n\n\n
\n
settings<\/code>:<\/strong> This is where we define WordPress presets and defaults; it\u2019s also where we can enable or disable certain WordPress features.<\/li>\n\n\n\n
styles<\/code>:<\/strong> This is where we define CSS for global and block-level theme styles.<\/li>\n\n\n\n
customTemplates<\/code>:<\/strong> This is where we register new custom theme templates. It\u2019s the equivalent of dropping a new PHP template file in a classic theme.<\/li>\n\n\n\n
templateParts<\/code>:<\/strong> This section contains modular pieces that can be included in templates. It\u2019s the equivalent of the
parts<\/code> subfolder you typically see in classic themes.<\/li>\n<\/ul>\n\n\n\n
settings<\/strong><\/code> and
styles<\/strong><\/code> sections. Both provide ways to configure the global styles of a WordPress block theme. So, let\u2019s look at each one and the various options we have to customize the theme appearance.<\/p>\n\n\n
The settings section (
settings<\/code>)<\/h3>\n\n\n
add_theme_support<\/code> function<\/a> you\u2019d reach for in a classic theme\u2019s
functions.php<\/code> file.<\/p>\n\n\n\n
{\n \"version\": 2,\n \"settings\": {\n \/\/ etc.\n }\n}<\/code><\/pre>\n\n\n\n
Supported features<\/h3>\n\n\n
settings<\/code> section and compares them to their equivalent
add_theme_support<\/code> function arguments.<\/p>\n\n\n\n
Theme JSON settings<\/th> add_theme_support<\/code><\/th><\/tr><\/thead>
color.custom<\/code><\/td>
custom-colors<\/code><\/td><\/tr>
color.palette<\/code><\/td>
editor-color-palette<\/code><\/td><\/tr>
color.gradients<\/code><\/td>
editor-gradient-presets<\/code><\/td><\/tr>
spacing.padding<\/code><\/td>
custom-spacing<\/code><\/td><\/tr>
spacing.units<\/code><\/td>
custom-units<\/code><\/td><\/tr>
typography.lineHeight<\/code><\/td>
custom-line-height<\/code><\/td><\/tr>
typography.fontSizes<\/code><\/td>
editor-font-sizes<\/code><\/td><\/tr>
useRootPaddingAwareAlignments<\/code><\/td>
N\/A<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n add_theme_support<\/code> in your classic theme to disable custom font sizes:<\/p>\n\n\n\n
<?php\nadd_theme_support(disable-custom-font-sizes);<\/code><\/pre>\n\n\n\n
theme.json<\/code> is the
settings.typography.customFontSize<\/code> property:<\/p>\n\n\n\n
{\n \"version\": 2,\n \"settings\": {\n \"typography\": {\n \"customFontSize\": false;\n }\n }\n}<\/code><\/pre>\n\n\n\n
spacing<\/code> controls, there are a number of
spacing<\/code>-related features we can individually enable:<\/p>\n\n\n\n
{\n \"version\": 2,\n \"settings\": {\n \"spacing\": {\n \"margin\": false,\n \"padding\": false,\n \"blockGap\": null,\n \"units\": [ \"px\", \"em\", \"rem\", \"vh\", \"vw\" ]\n },\n }\n}<\/code><\/pre>\n\n\n\n
settings<\/code> features that can be configured in
theme.json<\/code>:<\/p>\n\n\n\n
\n View full table <\/summary>\n \n\n
Setting<\/th> Feature<\/th> Data type<\/th><\/tr><\/thead> border<\/code><\/td>
radius<\/code><\/td>
Boolean<\/td><\/tr> <\/td> color<\/code><\/td>
Boolean<\/td><\/tr> <\/td> style<\/code><\/td>
Boolean<\/td><\/tr> <\/td> width<\/code><\/td>
Boolean<\/td><\/tr> color<\/code><\/td>
custom<\/code><\/td>
Boolean<\/td><\/tr> <\/td> customDuotone<\/code><\/td>
Boolean<\/td><\/tr> <\/td> customGradient<\/code><\/td>
Boolean<\/td><\/tr> <\/td> duotone<\/code><\/td>
Array<\/td><\/tr> <\/td> gradients<\/code><\/td>
Array<\/td><\/tr> <\/td> link<\/code><\/td>
Boolean<\/td><\/tr> <\/td> palette<\/code><\/td>
Array<\/td><\/tr> <\/td> text<\/code><\/td>
Boolean<\/td><\/tr> <\/td> background<\/code><\/td>
Boolean<\/td><\/tr> <\/td> defaultGradients<\/code><\/td>
Boolean<\/td><\/tr> <\/td> defaultPalette<\/code><\/td>
Boolean<\/td><\/tr> layout<\/code><\/td>
contentSize<\/code><\/td>
String<\/td><\/tr> <\/td> wideSize<\/code><\/td>
String<\/td><\/tr> <\/td> type<\/code><\/td>
String ( default<\/code> and
constrained<\/code>)<\/td><\/tr>
spacing<\/code><\/td>
margin<\/code><\/td>
Boolean<\/td><\/tr> <\/td> padding<\/code><\/td>
Boolean<\/td><\/tr> <\/td> blockGap<\/code><\/td>
String<\/td><\/tr> <\/td> units<\/code><\/td>
Array<\/td><\/tr> typography<\/code><\/td>
customFontSize<\/code><\/td>
Boolean<\/td><\/tr> <\/td> lineHeight<\/code><\/td>
Boolean<\/td><\/tr> <\/td> dropCap<\/code><\/td>
Boolean<\/td><\/tr> <\/td> fontStyle<\/code><\/td>
Boolean<\/td><\/tr> <\/td> fontWeight<\/td> Boolean<\/td><\/tr> <\/td> letterSpacing<\/code><\/td>
Boolean<\/td><\/tr> <\/td> textDecoration<\/code><\/td>
Boolean<\/td><\/tr> <\/td> textTransform<\/code><\/td>
Boolean<\/td><\/tr> <\/td> fontSizes<\/code><\/td>
Array<\/td><\/tr> <\/td> fontFamilies<\/code><\/td>
Array<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n<\/details>\n\n\n outline<\/code> and
border<\/code><\/a> properties to the Global Styles panel. They are included in this table before formal adoption.<\/p>\n\n\n
The