In the Code Block if I type in reversed character, they are encoded to HTML entities:

  • Input:

  • Output:

    <pre class="wp-block-code"><code>'&#91;] </code></pre>

Meanwhile, if I put them in the custom HTML block, the output characters aren't encode:

  • Input:

  • Output:

    <code class="'[]"></code>
    <code><code class="'[]"></code></code>
    <pre class="wp-block-code"><code>'[]</code></pre>

I wonder why this should be the case? I enable troubleshooting mode and use the Twenty Twenty-One theme.

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

  • 1
    This is the whole point of the code block. It’s for displaying actual code. You can’t do that if the characters aren’t encoded or it could be interpreted as HTML. Commented Jan 7, 2022 at 11:26
  • do you mean the code block, or the <code> tag? Because when I put it in the custom html block, the <code> tag doesn't encode the characters
    – Ooker
    Commented Jan 7, 2022 at 11:32

1 Answer 1


The Code Block is to display things just as you typed them, so it may encode to ensure no code actually executes.

The HTML block is the reverse - it is to execute code exactly as you typed it, so it doesn't encode.

This is intentional, so you can either show or execute code, depending on your needs. :)

  • Hmm, this answer seems to contradict with this answer in Why does the custom HTML block not preserve the HTML characters?. In particular, shouldn't the content in the code block be untouched by wptexturize()?
    – Ooker
    Commented Jan 8, 2022 at 7:42
  • 1
    @Ooker yes, texturize skips text enclosed in code tags, just like the ' in your Input which would remain as ' when the post content is displayed. And the Code block doesn’t encode many characters, but the block still encodes when and if needed. E.g. If it contains [ or <, then they'll be encoded/escaped so as to prevent the code from being executed by WordPress (in the case of [ - the opening character of a shortcode like [foo]) or the browser (in the case of < - the opening character of an HTML tag).
    – Sally CJ
    Commented Jan 9, 2022 at 10:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.