Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Heading block] Add a wp-block-heading CSS class (#42122)
## 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
- Loading branch information