Skip to content

Possibility to control allowed formats in core blocks independently #43084

Open

Description

@luislard

What problem does this address?

Provide the possibility to have different allowed formats for core/paragraph and core/heading:
Example:
core/paragraph should have ["core/bold", "core/italic", "link"]
core/heading should have [ ]

What is your proposed solution?

Looking at the code the formats are added by the format-library package in here

The formats are registered in a store and available for all rich text instances.

In the case of the core/heading:

I need a possibility to modify the allowedFormats props to be passed to the RichText instance created by it, the only place "allowedFormats" prop could be added is in here, so an approach to add props to a block could be via using the BlockEdit Hook like this:

/** @jsx createElement /
 /* @jsxFrag Fragment */
import {createElement, Fragment, useState} from '@wordpress/element';
import { createHigherOrderComponent } from '@wordpress/compose';
import { addFilter } from '@wordpress/hooks';
import { useSelect } from '@wordpress/data';


const removeUnwantedFormats = createHigherOrderComponent((BlockEdit) => {
    return (props) => {

        const selectedBlock = useSelect( ( select ) => {
            return select( 'core/block-editor' ).getSelectedBlock();
        }, [] );


        if (!selectedBlock || selectedBlock.name !== 'core/heading') {
            return (<Fragment>
                <BlockEdit {...props} />
            </Fragment>)
        }

        // its a "core/heading"
        
        const newProps = {
            ...props,
            allowedFormats: []
        }
        return (<Fragment>
            <BlockEdit {...newProps} />
        </Fragment>)
    }
}, 'removeUnwantedFormats');


addFilter(
    'editor.BlockEdit',
    'acme/removeUnwantedFormats',
        removeUnwantedFormats
);

When I debug why the prop is not reaching the rich text created by the core/heading is because in here It returns an object just with className and style.

In the case of "core/paragraph" similar can be achieved because we have this

Activity

  1. Mamaduka commented on Mar 28, 2025

    @Mamaduka
    Member

    Maybe we could allow per-block format configuration using an attribute. We're already doing something similar for allowedBlocks.

    @gziolo, @t-hamano, what do you think?

  2. self-assigned this
    on Mar 28, 2025
  3. Mamaduka commented on May 9, 2025

    @Mamaduka
    Member

    Related #16246.

  4. acketon commented on Jun 17, 2025

    @acketon

    My other issue was closed as duplicate of this, but I still wanted to add some thoughts:

    As a a block & theme developer one of the things that prevents me from using blocks like core/paragraph where I need a paragraph is that there are cases where I can't permit a format like inline-images. Just picking on that format for this example.

    For example imagine I'm building a simple block that is a promo box. It has a title attribute and then I need to support multiple paragraphs. However the RichText component's multiline support was deprecated so I can't use that anymore. The current recommendation is a lot more work: I need to add an InnerBlocks component and then allow Paragraph blocks inside there.

    But the core/paragraph block comes with a lot of out of the box capabilities by default. I can't disable those for all instances of the block in an entire theme. But at the same time in this use case I don't want to have to support the styling for the inline images format of the paragraph block inside this Promo block that is supposed to be simple.

    So now I'd have to create my own simpler my-promo-block/paragraph block as a child block of this promo block. That's a lot of extra technical debt to maintain.

    Instead it would be ideal to be able to have a method to control what formats are allowed in an existing block depending on the context of which it was loaded.

    When configuring an InnerBlocks component I can control which blocks are allowed inside that Innerblocks component. But I'd like to additionally be able to specify which allowedFormats for each of those blocks are allowed.

    I also think that allowedFormats in blocks should perhaps be controllable by theme.json at some point.

  5. mediaformat commented on Nov 24, 2025

    @mediaformat
    Contributor

    Adding to this, especially in light of the Block Bindings API and Block Variations, there is a need for Theme developers to be able to link data to core blocks while curating the Authoring experience.

    Maybe we could allow per-block format configuration using an attribute. We're already doing something similar for allowedBlocks.

    @gziolo, @t-hamano, what do you think?

    ^ This would be ideal, alternately a core/text block might be another way to solve the issue #73321

  6. mediaformat commented on Nov 24, 2025

    @mediaformat
    Contributor

    I think being able to disallow formatting via an allowedFormats attribute would be ideal, especially given the low overhead of declaring block variations even without needing a build process!

  7. Mamaduka commented on Dec 2, 2025

    @Mamaduka
    Member

    @mediaformat, that was my initial solution as well, but @fabiankaegy raised a good point in the previous PR - #69738 (comment).

    I'll try to create a new PR, based on the latest discussion.

  8. mediaformat commented on Dec 2, 2025

    @mediaformat
    Contributor

    That makes sense, supports was also the first placed I looked for control settings.

  9. intelligence commented on Apr 7, 2026

    @intelligence

    Any movement on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions