How to disable automatic ‘Smart Quotes’ for specific HTML elements.

By default WordPress will run the wptexturize() function on your post’s content, as output with the_content(). This converts common plain text characters into stylised entities, most notably changing straight single and double quotes into their curly equivalents.

'Lorem ipsum' dolor sit 'amet - "consectetur" adipiscing elit...

becomes:

‘Lorem ipsum’ dolor sit ‘amet – “consectetur” adipiscing elit…

Disable for a specific element

WordPress does not texturise the content of pre, code, kbd, style, script and tt elements by default. You can add to this list using the no_texturize_tags filter.

PHP
plugins/pw-examples/pw-examples.php

The above code is displayed using the Code block added by Advanced Gutenberg Blocks which outputs code in textarea elements before formatting it via JavaScript. Here we have added the textarea element so that quotes aren’t converted.

Disable for the entire post

You can stop WordPress ‘texturising’ any post content by removing the wptexturize function from the the_content filter.

PHP
plugins/pw-examples/pw-examples.php

Disable completely

While the above snippet will disable this feature from the main post content, it will still run in other places, for example when outputting the post title. Rather than finding and removing the function from all the relevant filters, we can disable the wptexturize function completely using the run_wptexturize filter.

PHP
plugins/pw-examples/pw-examples.php