• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (deprecated)
You are here: Home / Programming / unregisterFormatType() for Specific Block Type in Gutenberg

unregisterFormatType() for Specific Block Type in Gutenberg

Last updated on February 17, 2025 by Sal Ferrarello

The WordPress block editor (a.k.a. Gutenberg) allows formatting in RichText fields via the Formatting Toolbar API. Each type of formatting (e.g. Bold and Italic) is a formatType. Here we’ll look at removing one of these formatTypes from a specific block type (e.g. removing Bold from the core paragraph block).

Removing FormatType from All Blocks

We can remove a formatType from all blocks using the unregisterFormatType() method.

e.g. we can remove the bold formatType from all blocks with this JavaScript code.

wp.richText.unregisterFormatType('core/bold');

You can even run this from the browser console, leaving the bold formatType on blocks like the list but removing bold formatType from paragraphs.

With Bold FormatType

WordPress Gutenberg Block With Bold FormatType

Without Bold FormatType

WordPress Gutenberg Block Without Bold FormatType

Removing FormatType from One Block Type

This code removes the bold format type from the core/paragraph block (leaving bold for all other block types).

origBoldFormatType = wp.data.select('core/rich-text')?.getFormatType('core/bold');
if (origBoldFormatType) {
  const { edit } = origBoldFormatType;

  wp.richText.unregisterFormatType('core/bold');

  wp.richText.registerFormatType('core/bold', {
    ...origBoldFormatType,
    edit: (props) => {
      if ('core/paragraph' === wp.data.select('core/block-editor').getSelectedBlock()?.name) {
        // Do not render core bold formatType (i.e. no button, no keyboard shortcut).
        return null;
      }
      // Render the original bold formatType (i.e. button, keyboard shortcut).
      return edit(props);
    },
  });
}

This JavaScript code works by:
– storing a copy of the bold formatType in origBoldFormatType
– removing the bold formatType from all blocks
– registering a new formatType with the same core/bold name
– this new formatType has an if conditional in the edit function
– when the currently selected block is core/paragraph it returns null (rendering nothing)
– for any other block type, the edit function from the origBoldFormatType is used (rendering the bold formatType)

The result is the bold formatType appears for all blocks except core/paragraph.

This can also be run from the browser console.

Bold formatType removed from core/paragraph but remains on blocks like the list block.

Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP and JavaScript developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a principal engineer.

Filed Under: Dev Tips, Programming, Solution Tagged With: Gutenberg, WordPress

Reader Interactions

Comments

  1. Turan says

    April 5, 2025 at 5:40 am

    Thank you, you’re a lifesaver! I lost half my hair as I couldn’t find a solution for removing bold and italic from core/button.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2026 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in