0

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?

14
  • 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
    Jan 4 at 23:56
  • which editor are you referring to, is this the classic editor?
    – Tom J Nowell
    Jan 5 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
    Jan 5 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
    Jan 5 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
    Jan 5 at 11:14

1 Answer 1

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
    1 hour ago

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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