For example it seems that the plain single-quote character ' (') is converted to the right ones (’) in the HTML page output. I understand the reason for this in regular Gutenberg blocks, but why does it still need to be done in the custom HTML block? I enable troubleshooting mode and use the Twenty Twenty-One theme and it's still converting.

Here are the different between the input methods:

<p>Paragraph block then converted to html: &#8216;</p>
Custom HTML block: &#8216;
<pre class="wp-block-preformatted">Preformatted block: '</pre>
<pre class="wp-block-code"><code>Code block: '</code></pre>
<pre>Classic block with preformatted style: '</pre>

My goal is to preserve the characters so that I can make inputs for Cypher. A piece of JS is in the post to handle this input.

FYI: A piece of JS code is needed to use multiple times with different values and function names. How to do it efficiently?

  • Have you disabled all plugins and changed to a default theme to verify the problem is still occurring? the_content & get_the_content doesn't change the character encoding. Mayve it's 1.) coming from elsewhere in your theme or a plugin or 2.) something related to Gutenberg that's maybe changing the character before it's saved?
    – admcfajn
    Commented Jan 4, 2022 at 23:56
  • which editor are you referring to, is this the classic editor?
    – Tom J Nowell
    Commented Jan 5, 2022 at 1:00
  • @admcfajn I enable troubleshooting mode and use the Twenty Twenty-One theme and it's still converting. If that's 2, then how can I investigate this?
    – Ooker
    Commented Jan 5, 2022 at 9:00
  • 1
    in this case, you need to wrap your syntax in something such as code tags otherwise there is nothing to prevent plugins or features from interpreting quotes as quotes and modifying them to be helpful, e.g the texturize feature
    – Tom J Nowell
    Commented Jan 5, 2022 at 11:13
  • 1
    I would expect that you would have built a cipher block to do this, which would have bypassed this issue completely as well as giving you the option of showing a preview in the editor. A block that just has a text area input would have been enough UI
    – Tom J Nowell
    Commented Jan 5, 2022 at 11:14

1 Answer 1


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

  • 1
    i have a <script> block where wordpress puts <p></p> on empty lines and encodes some & as &#038;. i don't understand how to prevent wordpress from changing the & or why it only happens to some & and not others
    – Jayen
    Commented Dec 7, 2022 at 21:32
  • @Jayen that has nothing to do with my answer, or this question. If you have a new question you should ask a new question, don't spam other questions that have the same theme. Also stop putting script tags inside html blocks, that's not what they're for, and inline JS inside post content is dangerous and it rightly gets stripped out or escaped by WordPress. The solution to how you do what you're trying to do is don't, that's not how you put JS in a post
    – Tom J Nowell
    Commented Dec 8, 2022 at 12:57
  • 1
    Sorry, maybe I didn't understand your answer. You said "Text enclosed in the tags <pre>, <code>, <kbd>, <style>, <script>, and <tt> will be skipped" so now I'm not understanding why the text in my <script> is not being skipped. Can you tell me how I should put JS in a page?
    – Jayen
    Commented Dec 8, 2022 at 20:17
  • not by writing it into a block inside the editor, if you are able to do that then you should consider it a major security risk, lots of questions on the site already ask how to run javascript inside a posts content, I'm not going to repeat them in comments. The original author isn't trying to execute javascript, they're trying to display it as code the same way this site embeds code blocks for viewing
    – Tom J Nowell
    Commented Dec 8, 2022 at 22:53

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.