Disable Gutenberg text-Settings in all blocks

The closest I can find in the documentation is disabling custom font size (the text input) and forcing the dropdown font size to only contain “Normal”.

add_action('after_setup_theme', 'wpse_remove_custom_colors');
function wpse_remove_custom_colors() {
    // removes the text box where users can enter custom pixel sizes
    add_theme_support('disable-custom-font-sizes');
    // forces the dropdown for font sizes to only contain "normal"
    add_theme_support('editor-font-sizes', array(
        array(
            'name' => 'Normal',
            'size' => 16,
            'slug' => 'normal'
        )
    ) );
}

Note this may not work for non-Core blocks – they may have their own way of registering font size etc. that isn’t affected by theme_support. Hoping someone else from the community knows how to disable the drop caps as well.

Update: a way to remove Drop Caps

This wouldn’t be my preferred method, because you can still add a Drop Cap in the editor and it just doesn’t render in the front end, but it’s all I have been able to achieve so far:

There is a render_block() hook where you can change what renders on the front end without changing what shows in the editor or gets saved to the database.

add_filter('render_block', function($block_content, $block) {
    // only affect the Core Paragraph block
    if('core/paragraph' === $block['blockName']) {
        // remove the class that creates the drop cap
        $block_content = str_replace('class="has-drop-cap"', '', $block_content);
    }
    // always return the content, whether we changed it or not
    return $block_content;
}, 10, 2);

This method changes the outer appearance rather than the actual content, so that if you ever wanted to allow drop caps, you could just remove the filter and all the ones that people had added in the editor would suddenly appear.

Leave a Comment