You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Remove heading settings (levels) from core/heading #20213
Yea, this would be great. Also perhaps allow renaming? A scenario that we are hitting and I am having a hard time imagining to be uncommon, is that h1 is actually used for the page title, so there should really only be a single h1. Then everything below that would just be regular headers that can show up any number of times. Most wikis and rich text editors appear to have adopted a style where there is a page title and then header 1, header 2, etc. Sinc there is no real concept of the title in HTML, the title should be represented as h1 and Header 1 should actually be h2 to everything makes sense semantically. Or am I barking up the wrong tree here?
This is required.
I only want the editors of the site to be able to set H2, H3, and H4.
If there is a way to limit the H block to a subselection can someone illuminate me?
Reacted by Josh Espinoza, Ted Whitehead, Joshua Dorenkamp, loopmasta and James Macon
Currently the heading block allows users to insert any heading level from 1 to 6. This is nice and flexible but in some instances, it would be good to be able to restrict this, for example, only allow 2-6 or 2-3 (in the same way that we can restrict spacing, colours, remove blocks etc.).
One solution would be to use the theme.json settings mechanism to implement a new setting (maybe under typography?) called headingLevels, which would be an array that would some or all of the numbers between 1 and 6.
We can then use this array (if it exists) instead of the hard coded array in block-library/src/heading/heading-level-dropdown.js.
The only thing that gives me pause about this approach is that core/heading is the only block that this setting would get applied to. This struck me as odd at first, but on reflection, I don't think it is a big deal. After all there is no rule that says settings need to apply to multiple blocks and AFAIK, there is not a method for defining a setting for a particular block.
Thinking about alternative approaches, I wondered if a block hook (e.g. editor.BlockEdit might be able to help. Perhaps in conjunction with adding an extra prop to the component. Not sure if this is a good approach or there is a precedent for doing it this way in Gutenberg.
And maybe there is another approach I am not thinking of. How have we solved similar problems in the past?
This PR by @carolinan Add a tag selection component to replace HeadinglevelDropdown #46003
Can use some feedback from anyone who has commented in this issue.
Activity
mkaz commentedon Feb 13, 2020
I don't recommend that approach. It might be possible to modify the core heading block, but not advisable.I would combine two approaches:
First disable the core header using the
wp.blocks.unregisterBlockType( 'core/heading' );See this block filters documentationSecond, create your own heading block that inserts just an H1 tag. See the block tutorial it explains how to create a rich text block, switch the
Ptag with anH1tag and it should do what are looking for.I created a rough example to try it out. See this branch of my test-block: https://github.com/mkaz/test-block/tree/remove-heading
urlund commentedon Sep 11, 2020
+1 for option to disable heading levels ;)
tdapper commentedon Nov 16, 2020
Yea, this would be great. Also perhaps allow renaming? A scenario that we are hitting and I am having a hard time imagining to be uncommon, is that
h1is actually used for the page title, so there should really only be a singleh1. Then everything below that would just be regular headers that can show up any number of times. Most wikis and rich text editors appear to have adopted a style where there is a page title and then header 1, header 2, etc. Sinc there is no real concept of the title in HTML, the title should be represented ash1and Header 1 should actually beh2to everything makes sense semantically. Or am I barking up the wrong tree here?wwdes commentedon Feb 9, 2021
+1
steveangstrom commentedon Aug 26, 2021
This is required.
I only want the editors of the site to be able to set H2, H3, and H4.
If there is a way to limit the H block to a subselection can someone illuminate me?
pwkip commentedon Mar 1, 2022
I achieve this with some CSS included in the backend:
[aria-label="Heading 1"], [aria-label="Heading 5"], [aria-label="Heading 6"] { display: none; }Technically you could still add h1, h5 and h6 in the code editor, but for my use case this is sufficient.
skorasaurus commentedon Nov 10, 2022
Copying @michaelMcAndrew's description of this issue at who wrote his issue at #42634
paaljoachim commentedon Feb 1, 2023
This PR by @carolinan
Add a tag selection component to replace HeadinglevelDropdown
#46003
Can use some feedback from anyone who has commented in this issue.
datgausaigon commentedon Jul 7, 2024
Hi all,
Is there any way we can do this now? I tried the following code but it doesn't work.
Thanks ❤️
ndiego commentedon Jul 15, 2024
A proposed solution is available in #63535