Block Editor PHP Intermediate

Remove Custom Colours and Font Sizes

Make editors choose from your theme's palette and font sizes only, by removing the custom colour picker and size input.

Tested on WordPress 7.1 PHP 8.3 No plugin needed Updated
functions.php 15 lines
add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) {
	return $theme_json->update_with( [
		'version'  => 3,
		'settings' => [
			'color'      => [
				'custom'         => false,
				'customGradient' => false,
				'customDuotone'  => false,
			],
			'typography' => [
				'customFontSize' => false,
			],
		],
	] );
} );

Where to add this

Recommended A code snippets plugin Survives theme changes and is easy to switch off.
Child theme At the end of your child theme's functions.php file.
Must-use plugin As a .php file in wp-content/mu-plugins, starting with <?php.

Always add PHP to a staging site first, or have FTP or file manager access ready, so you can undo it if something goes wrong.

Brand guidelines fall apart when everyone can pick any colour and any font size. This snippet limits editors to the palette and sizes your theme defines.

How it works

WordPress builds editor settings from theme.json. The wp_theme_json_data_theme filter lets you change the theme’s settings in PHP, even if the theme has no theme.json file. Turning off custom, customGradient, customDuotone and customFontSize removes the free colour pickers and the custom size field, leaving only the presets.

This works for classic themes and block themes.

Things to watch

  • Make sure your theme defines a colour palette and font sizes first, or editors will have no colour options at all.
  • Content already using custom colours keeps them.

How to test it

Select a paragraph and open the colour panel. You should see the palette but no “Custom color” picker.

This website uses cookies to enhance your browsing experience and ensure the site functions properly. By continuing to use this site, you acknowledge and accept our use of cookies.

Accept All Accept Required Only