Why does the custom HTML block not preserve the HTML characters?

This is caused by wptexturize and the use of a standard <div> to contain your code. See https://developer.wordpress.org/reference/functions/wptexturize/

Instead, markup code as code:

Text enclosed in the tags <pre>, <code>, <kbd>, <style>, <script>, and <tt> will be skipped. This list of tags can be changed with the no_texturize_tags filter.

Note that the HTML block just allows you to insert user defined HTML into the post content, that post content still gets processed, it’s a block with HTML, not a raw arbitrary HTML block, e.g. if you put a shortcode inside it, the shortcode gets processed. A paragraph inside a HTML block is just as much a paragraph as a paragraph inside a paragraph block. Likewise you might discover some tags get stripped out if you don’t have the unfiltered_html capability

Leave a Comment