Halloween Sale 15% off Ends in See the plans
PHP

Lock the Editor to Theme Colors and Font Sizes

Removes the custom color picker, default palettes and custom font sizes from the block editor, so editors can only use your theme's brand styles.

Don’t have WPIDE yet? Install it on your site

Code

add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) {
    return $theme_json->update_with( array(
        'version'  => class_exists( 'WP_Theme_JSON' ) && defined( 'WP_Theme_JSON::LATEST_SCHEMA' ) ? WP_Theme_JSON::LATEST_SCHEMA : 3,
        'settings' => array(
            'color'      => array(
                'custom'          => false,
                'customGradient'  => false,
                'customDuotone'   => false,
                'defaultPalette'  => false,
                'defaultGradients' => false,
                'defaultDuotone'  => false,
            ),
            'typography' => array(
                'customFontSize'   => false,
                'defaultFontSizes' => false,
            ),
        ),
    ) );
} );

Notes

If your theme defines no palette or font sizes of its own, editors are left with none to choose from.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.