How to lock down colors and fonts in a WordPress block theme

Out of the box, the block editor lets anyone pick any color and any font size for any block. That’s great on your own site, but on a client site with a carefully chosen design, you can end up with lime green headings and paragraphs with a font size and line length from Wikipedia of old.

A block theme can take the free pickers away with a few lines in theme.json, so the only colors and font sizes left are the ones in the theme’s design. In this tutorial, we’ll go through the settings for colors and fonts, how to lock down a single block, and what theme.json can’t lock down on its own.

Before we start, let’s acknowledge that opinions differ on whether websites should restrict the client’s control at all. My approach here is usually to remove default options that could lead the client astray, like the default gradients, but not restrict them from adding custom gradients and colors of their own, if they choose to. I have worked on projects where the client has asked to have their options restricted though, so there’s clearly a place for it.

Locking down colors

Add this to the settings section of your theme’s theme.json. If you’re using a theme you didn’t make, add it to the theme.json of a child theme instead, so it isn’t lost the next time the theme updates.

"color": {
"custom": false,
"customDuotone": false,
"customGradient": false,
"defaultDuotone": false,
"defaultGradients": false,
"defaultPalette": false
}
  • custom, customGradient and customDuotone remove the color pickers for custom colors, gradients and duotone filters. Clicking a color setting on a block now only shows the swatches from the theme’s palette.
  • defaultPalette, defaultGradients and defaultDuotone remove the colors, gradients and duotone filters that come with WordPress, like “Vivid cyan blue” and “Luminous vivid orange”. Without them, the theme’s own palette is all that’s left.

If your theme already has a color section in its settings, add the lines to it instead of adding a second one. Twenty Twenty-Five, for example, already turns off the three default options, so it only needs the first three lines.

Locking down font sizes and fonts

Font sizes work the same way. Add this to the settings section:

"typography": {
"customFontSize": false,
"defaultFontSizes": false
}
  • customFontSize removes the option to set a font size in pixels or other units. The font size control in the block settings now only has the theme’s sizes, like S, M, L and XL.
  • defaultFontSizes removes the font sizes that come with WordPress, so only the theme’s sizes are left.

Fonts are a little different. The font picker only lists the fonts the theme has added, so there are no free choices to turn off. But anyone who can open “Styles” in the Site Editor can add new fonts with the Font Library. If you don’t want that, I’ve written a separate tutorial on how to turn off the Font Library.

Locking down a single block

The same settings work for single blocks, under settings.blocks. You can also turn off a setting completely, so it doesn’t show up at all. This removes the background color from the Paragraph block, but leaves it on every other block:

"blocks": {
"core/paragraph": {
"color": {
"background": false
}
}
}

That’s useful when a setting makes sense on some blocks but not others. Background colors on a Group block can be part of the design, while a paragraph with a yellow background usually isn’t. Removing settings that the client won’t ever use also has the added benefit of simplifying the editor, but it can be dangerous to make those assumptions.

What theme.json can’t lock down

These settings lock down the editor, but not the Site Editor. Anyone who can open “Styles” can still change the design there:

  • Under “Colors” → “Palette”, they can edit the theme’s colors, add custom colors to the palette, and switch to one of the theme’s other color palettes. Custom colors added there show up in every block’s color settings.
  • Under “Typography”, they can edit the font size presets, and add fonts with the Font Library.

The Site Editor is only open to users who can edit the theme, which by default means Administrators. So the simplest way to keep a client out of it is to give them the Editor role instead. Editors can write and edit everything on the site, but can’t open the Site Editor, and with the settings above, they can only use the colors and font sizes in your design. Here I will put my foot down, though. When you build sites for clients, I think they should always have full access to their site, and that includes an administrator account. If you want both, give them an administrator account for when they need it, and an editor account for their everyday editing.

Notes

  • Existing content keeps its colors. Blocks that already have a custom color or font size keep it. The settings only remove the option to pick new ones, so go through the important pages if you want them to match the design.
  • Locking blocks is a different thing. If you want to stop a client from moving or removing blocks in a template, use block locking instead, under “Lock” in the block’s options menu.