Remove ‘Custom..’ option in tinyMCE colour swatch

Yes, it is possible to remove the custom colors option from tinyMCE.

WordPress bundles a tinyMCE plugin to handle the custom colors functionality. The tiny_mce_plugins filter can be used to remove this bundled plugin which is identified by the key colorpicker.

Note that removing the custom colors option will not affect users’ ability to select colors using the default color swatches.

/**
 * Remove the Color Picker plugin from tinyMCE. This will
 * prevent users from adding custom colors. Note, the default color
 * palette is still available (and customizable by developers) via
 * textcolor_map using the tiny_mce_before_init hook.
 * 
 * @param array $plugins An array of default TinyMCE plugins.
 */
add_filter( 'tiny_mce_plugins', 'wpse_tiny_mce_remove_custom_colors' );
function wpse_tiny_mce_remove_custom_colors( $plugins ) {       

    foreach ( $plugins as $key => $plugin_name ) {
        if ( 'colorpicker' === $plugin_name ) {
            unset( $plugins[ $key ] );
            return $plugins;            
        }
    }

    return $plugins;            
}

Leave a Comment