Repository navigation
Description
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
Mamaduka commentedon Mar 28, 2025
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?
Mamaduka commentedon May 9, 2025
Related #16246.
acketon commentedon Jun 17, 2025
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/paragraphwhere 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/paragraphblock 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/paragraphblock 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.
mediaformat commentedon Nov 24, 2025
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.
^ This would be ideal, alternately a core/text block might be another way to solve the issue #73321
mediaformat commentedon Nov 24, 2025
I think being able to disallow formatting via an
allowedFormatsattribute would be ideal, especially given the low overhead of declaring block variations even without needing a build process!Mamaduka commentedon Dec 2, 2025
@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.
mediaformat commentedon Dec 2, 2025
That makes sense,
supportswas also the first placed I looked for control settings.intelligence commentedon Apr 7, 2026
Any movement on this?