I try since a while to style the ordinary list block with wordpress theme.json.
"blocks": {
"core/list": {
"color": {
"text": "red"
}
},
"core/list-item": {
"style": "disc",
"indent": "2em",
"spacing": "5px"
}
},
while the core/list
item takes the color "red"
as expected, I can’t get further styles to the <li>
items.
Is there something I’m missing or does theme.json really doesn’t support that?
Thanks for any help!
2
Answers
I suggest always referring to the theme.json schema. You can find it at https://raw.githubusercontent.com/WordPress/gutenberg/trunk/schemas/json/theme.json.
Analyzing the schema, you will see that some styles/options/values are expressed slightly differently.
For example, this is how you would set some of them:
That said, some options are not available. For example, I couldn’t find a way to set the disc style. It should be possible to add custom CSS rules but I couldn’t figure out how to apply the
list-style-type:disc
rule.Also, I suggest you set the "schema" property at the top of the theme.json file. This way, the editor you are using will be able to suggest the available properties as you write them. You can set the schema in this way:
Take a look at https://fullsiteediting.com for other handy information about how to set up theme.json.
Alternatively to setting the styles within the
theme.json
settings, you can add your own inline styles with thewp_enqueue_block_style()
function. This function will load your custom CSS whenever the block is appended to the current page.At the time of writing the amount of control you get from the
theme.json
file is limited. This allows you full control over the styles.