Does theme.json only work with block based theme ?
-
Hi updated to latest version of wordpress 5.8 , I am seeing that the default theme “twenty twenty one”, haven’t come with any theme.json file. I tried to add it manually in the theme and added some setting like color, spacing etc. But nothing is working in block editor. Only the settings I provide through functions.php file works.
Wordpress blog announces that it now support theme.json file, if yes, that it should work with any theme I guess. But its working for only block based theme. Can anybody know if theme.json file can be used with classic themes or not ?
- This topic was modified 3 years, 2 months ago by Jan Dembowski. Reason: Moved to Fixing WordPress, this is not an Developing with WordPress topic
-
You can read more about theme.json at https://make.wordpress.org/core/2021/06/25/introducing-theme-json-in-wordpress-5-8/
Hi @t-p ,
I am already aware about this doc link and also https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-json/ , also detailed documentation on using blocked based theme and using theme.json file is mentioned here https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-json/
But I am not saying that theme.json file is not working, its working well with block based theme. I have already created my custom block based theme too. But the issue is that its not working with a classic theme, not even in the default wordpress theme “twenty twenty one”, that come with wordpress 5.8
I asked around more knowledgeable folks, this what I was told :
It should work with any theme, but it's only going to be useful for themes that really go full block editor. Outside of that I'm not sure what the value is Depends on what you mean by "block based" I guess.
- This reply was modified 3 years, 2 months ago by t-p.
Hi!
The theme.json file works with any theme, but it is not a “drop-in” file, some themes will need adjustments.
It can be used with any theme, but if the theme already styles blocks or has very specific CSS, (like the dark mode in Twenty Twenty-One) the result will vary.
The themes own code may override what you add in theme.json.Twenty Twenty-One is not adapted to work with a theme.json file.
Adapting it may break backwards compatibility for users who are not upgrading to 5.8, and child themes.
It would also take a significant effort to make such a large update of the existing CSS, that it might never be adapted.There is work on adding template editing to Twenty Twenty-One, without the theme.json file. That will hopefully be completed soon.
If you want to use Twenty Twenty-One, but with a theme.json file, you can test TT1-Blocks, but you will need to activate the Gutenberg plugin.
Hi @poena ,
As per your saying theme.json file work with any theme, means either classic (php based theme) or block based theme (html template).
So I have created my own custom theme (two version, one is classic php based and another is block based). Block based theme.json file is working prefect, for example it applying color palette settings in block editor in wp-admin. But the same setting when I provide in classic version of that same theme, its not working. I want to know what I am missing there?
I apply this code in functions.php file for color palette and it works
// Editor color palette. $primary = '#0d6efd'; $secondary = '#ffc107'; $black = '#000000'; $white = '#FFFFFF'; add_theme_support( 'editor-color-palette', array( array( 'name' => esc_html__( 'Primary', 'uniquelang' ), 'slug' => 'primary', 'color' => $primary, ), array( 'name' => esc_html__( 'Secondary', 'uniquelang' ), 'slug' => 'secondary', 'color' => $secondary, ), array( 'name' => esc_html__( 'Black', 'uniquelang' ), 'slug' => 'black', 'color' => $black, ), array( 'name' => esc_html__( 'White', 'uniquelang' ), 'slug' => 'white', 'color' => $white, ), ) );
But when I add this code in theme.json file it not apply or override settings added in functions.php
"settings": { "color": { "palette": [ { "slug": "black", "color": "#000", "name": "Black" }, { "slug": "white", "color": "#fff", "name": "White" }, { "slug": "bsprimary", "color": "#0dcaf0", "name": "BSPrimary" }, { "slug": "bssecondary", "color": "#ffc107", "name": "BSSecondary" } ] } }
I also commented functions.php file settings to see what happen, but then default block editor color palette shows when we edit a page, and not the colors that I have mentioned in theme.json file.
So do we need to add some kind of add_theme_support function for enabling theme.json file support in php based themes ?
Hi!
Did you include the version number at the top of the theme.json file?
5.8 supports version 1.{ "version": 1, "settings": { ... }, "styles": { ... } }
Is WP_DEBUG enabled? If the theme.json is not correct, it should show an error message.
Hi @poena ,
Yes I have added version 1 and after debugging I found following error
Notice: Error when decoding a theme.json schema at path ...../wp-content/themes/unique-theme-blank/theme.json Syntax error in ....../wp-includes/class-wp-theme-json-resolver.php on line 69 Notice: Error when decoding a theme.json schema at path ....../wp-content/themes/unique-theme-blank/theme.json Syntax error in ....../wp-content/plugins/gutenberg/lib/class-wp-theme-json-resolver-gutenberg.php on line 77
This is my whole theme.json code
{ "version": 1, "settings": { "color": { "palette": [ { "slug": "black", "color": "#000000", "name": "Black" }, { "slug": "yellow", "color": "#EEEADD", "name": "Yellow" }, { "slug": "white", "color": "#FFFFFF", "name": "White" } ], }, "layout": { "contentSize": "610px", "wideSize": "1240px" }, "typography": { "fontFamilies": [ { "fontFamily": "system-ui,-apple-system,\"Segoe UI\",Roboto,\"Helvetica Neue\",Arial,\"Noto Sans\",\"Liberation Sans\",sans-serif", "slug": "system-font", "name": "System Font" }, { "fontFamily": "SFMono-Regular,Menlo,Monaco,Consolas,\"Liberation Mono\",\"Courier New\",monospace", "slug": "monospace-font", "name": "Monospace Font" } ] } } }
- This reply was modified 3 years, 2 months ago by hozefasmile.
- This reply was modified 3 years, 2 months ago by hozefasmile.
Ok I find out there was some error in the json file, comma needed to be removed. Now the settings also working.
Thanks a lot @poena for figuring out.
Can I remove all the settings in functions.php file? all the custom theme settings applied. Because now I am using theme.json for that?
For example these theme supports codesadd_theme_support( 'title-tag' ); add_theme_support( 'post-formats', array( 'link', 'aside', 'gallery', 'image', 'quote', 'status', 'video', 'audio', 'chat', ) ); add_theme_support( 'post-thumbnails' ); set_post_thumbnail_size( 1568, 9999 ); add_image_size('small', 120, '', true); // Small Thumbnail add_image_size('custom-size', 700, 200, true); $logo_width = 300; $logo_height = 100; add_theme_support( 'custom-logo', array( 'height' => $logo_height, 'width' => $logo_width, 'flex-width' => true, 'flex-height' => true, 'unlink-homepage-logo' => true, ) ); add_theme_support( 'customize-selective-refresh-widgets' ); add_theme_support( 'wp-block-styles' ); add_theme_support( 'align-wide' ); add_theme_support( 'custom-background', array( 'default-color' => 'd1e4dd', ) ); $primary = '#0d6efd'; $secondary = '#ffc107'; $black = '#000000'; $white = '#FFFFFF'; add_theme_support( 'editor-color-palette', array( array( 'name' => esc_html__( 'Primary', 'uniquelang' ), 'slug' => 'primary', 'color' => $primary, ), array( 'name' => esc_html__( 'Secondary', 'uniquelang' ), 'slug' => 'secondary', 'color' => $secondary, ), array( 'name' => esc_html__( 'Black', 'uniquelang' ), 'slug' => 'black', 'color' => $black, ), array( 'name' => esc_html__( 'White', 'uniquelang' ), 'slug' => 'white', 'color' => $white, ), ) ); add_theme_support( 'responsive-embeds' ); add_theme_support( 'custom-line-height' ); add_theme_support( 'custom-spacing' );
Hi
You can’t remove all of them if you want to keep the support for them.You can remove:
add_theme_support( 'editor-color-palette' )
(Now under settings, color)
add_theme_support( 'align-wide' );
( Now Under settings, layout)You can also replace
add_theme_support( 'custom-line-height' ); add_theme_support( 'custom-spacing' );
by adding that to theme.json.
You can remove
add_theme_support( 'title-tag' );
from block themes only.@poena , do you have a link to any doc reference file, where mentioned what all attributes and values are available for theme.json in wp 5.8 ? Because I am seeing that few settings that are mentioned at https://developer.wordpress.org/block-editor/how-to-guides/themes/theme-json/ are mentioned but not work. For example “customMargin” under “spacing”, I add it in theme.json, but not work in editor, only padding work.
Hi,
that is the most complete and official documentation.Not all blocks have editor controls for all settings,
but all blocks can have default margin and padding in theme.json.Also, you will find that, the default that you select, does not show up as the default value in the control.
To show which block supports what,
I added a block reference to https://fullsiteediting.com/block-reference/ but:
1: It is not up to date (I will try to fix that this weekend)
2: It shows what is supported in Gutenberg, not WordPress core.@poena , thanks for this valuable resource.
I was thinking the margin should work like padding work for blocks, for example in group or cover block we see padding under spacing like this https://ibb.co/GdDKLvj , but there is no such option to provide margin. I think margin parameter is only for setting some default margin for any particular block, am I right ?
- The topic ‘Does theme.json only work with block based theme ?’ is closed to new replies.