-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Site Title: Add levelOptions
attribute to control available heading levels
#64111
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: +34 B (0%) Total Size: 1.76 MB
ℹ️ View Unchanged
|
Followup to #63535
What?
This PR adds a
levelOptions
attribute to the Site Title block that allows developers to control which heading levels are available in the UI.Why?
Being able to restrict the available heading levels is crucial in many situations, whether it be general Editor curation, accessibility, block governance, SEO, etc.
How?
This PR adds a
levelOptions
attribute to the Site Title block that allows developers to define which heading levels should be displayed in the Heading dropdown UI. The approach is very simple and does not require a depreciation. Any previously set heading levels are respected in the markup.Note
Note that the available heading levels were previously hardcoded. I've moved these to the
default
property on thelevelOptions
attribute inblock.json
.With this new attribute, you can restrict the UI in many different ways, making this approach very flexible and powerful. For example, you could restrict options directly in block markup for a pattern or template. Try copying and pasting the following in the Editor.
Or you could modify the attribute programmatically via filters. The following will disable h1 globally. You could also add conditionals for post type, user permissions, etc. There are filters for both PHP and JavaScript so the applications are endless.
Testing Instructions
functions.php
file of your theme and see thath1
is disabled.Screenshots or screencast
With restrictions applied: