%%tb-image-alt-text%%

A new system for simply and reliably updating HTML attributes

Author: WordPress.org

Date: August 19, 2022 

Category: Make WordPress Core

This call for feedback will be open until September 9th.

Let’s introduce a reliable tool WordPress could use to adjust the HTML block markup. The current practice of using basic replacements seems fine at a first glance but is easy to break. The system proposed here will help avoid these common pitfalls.

Consider this example of adding a style HTML attribute in the cover block:

preg_replace( '/class=".*?"/', '${0} style="' . $styles . '"', $html );

It assumes a specific HTML structure:

There is a class attributeThe style attribute isn’t already defined, as browsers ignore the repeated attributes.There is no other

This is the first part of the article “A new system for simply and reliably updating HTML attributes“
written by WordPress.org.