Lock Colors and Sizes to the Theme Presets
Removes the custom color picker, custom gradients and free-form font and spacing sizes from the editor, so editors can only choose from your theme's palette and scales.
Opens WPIDE on
Code
add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) {
return $theme_json->update_with( array(
'version' => 3,
'settings' => array(
'color' => array(
'custom' => false,
'customGradient' => false,
'customDuotone' => false,
),
'typography' => array(
'customFontSize' => false,
),
'spacing' => array(
'customSpacingSize' => false,
),
),
) );
} );
Notes
Existing content with custom values keeps them. Works with block and classic themes.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.