2

I need to disable the Gutenberg text-settings tab in all Blocks. Is this possible with a funtion in funtions.php?

I could disable the colors tab, but found no solution for the text-settings:

function disable_tabs() {
    add_theme_support( 'editor-color-palette' );
    add_theme_support( 'disable-custom-colors' );
}
add_action( 'after_setup_theme', 'disable_tabs' );

The text-settings tab

  • 1
    Do you mean in all paragraph blocks ? – birgire Jan 24 at 14:20
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.