-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Styling set on the core/heading block of theme.json gets applied to all h1, h2, h3, etc. #42082
Comments
I am able to reproduce this with Gutenberg active, but not with only WordPress 6.0. @WordPress/block-themers Do we need to add the I don't remember the arguments against adding the class from the start, it might have been related to there being so many headings on some pages, like archives, that adding the class would be cluttering. |
I'm seeing this behavior with Gutenberg deactivated as well. |
I thought NOT leveraging a |
It would change heading element styles for themes that has relied on this "feature" until now... |
Aside: We will probably need to add the class to the paragraph block as well: #35323 |
The solution to this will be to add a |
This is blocked by #42485 |
## What? This PR adds the `wp-block-heading` CSS class to the heading block. It happens server-side so: * The class couldn't be accidentally removed from the serialized markup * There's no need to migrate the existing posts ## Why? Without the classname, global styles can't distinguish between the `h1-h6` elements that belong to the heading block vs ones that don't. As a result, [the styles set on the `core/heading` block of theme.json gets applied to all h1, h2, h3, etc](#42082) ## How? This PR transforms the stored `heading` block markup into one with an additional class name using [WP_HTML_Tag_Processor](https://make.wordpress.org/core/2022/08/19/a-new-system-for-simply-and-reliably-updating-html-attributes/). ## Alternatives considered I explored leaning on `get_block_wrapper_attributes`, but it falls short: * It infers attributes from globals. * It only processes the `style` and `class` properties, meaning a heading block with an anchor set would lose its `id`. * It ignores any additional attributes inside of the block content. * We'd still need to some parsing to remove the wrapping block from `$content`. ## Testing Instructions 1. Create a new page 2. Add a few heading blocks 3. Align text to right in one of them 4. Add a custom CSS classname in another 5. Save 6. Visit the page, confirm the rendered headings have the `wp-block-heading` css class
can someone verify in the latest build (trunk) (which has #42122) that this is fixed? |
This is fixed by #46284 |
This is still not possible, I'm no longer sure what the correct solution is. |
What are we missing here? I can no longer reproduce the original issue; adding the proposed styles to theme.json results in
|
I think there is some confusion (for me at least!) about the priority of element styles vs block styles. If a theme sets heading element styles and block styles, the block takes priority over the elements. This means that you should only set colors for a heading block if you want heading blocks to look different from other blocks. If you want them to all match then use elements. I agree @tellthemachines I think we can close this. |
Description
Styles set on
styles.blocks.core/heading
oftheme.json
are applied as markup that effects all h1, h2, h3, h4, etc. tags. This means unless HTML heading tags have their own explicitly set styles that would overridestyles.blocks.core/heading
, they inherit that.For example, setting
in theme.json results in the generated inline css of
Uses of HTML heading tags elsewhere in the theme (for example
core/post-title
) then have the styles forcore/heading
applied, unless they are specifically overridden.This also causes inconsistency between posts/pages that do and don't have the Heading block in them, as the above inline CSS is only inserted on those posts/pages that include a Heading block somewhere (see wpengine/frost#96).
Step-by-step reproduction instructions
core/heading
(as above)Screenshots, screen recording, code snippet
No response
Environment info
Wordpress 6.0, Twenty Twenty Two 1.2, Gutenberg 13.5.2
Please confirm that you have searched existing issues in the repo.
Yes
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Yes
The text was updated successfully, but these errors were encountered: