Curlies in code examples: the eternal curse of WordPress
-
I don’t know why it took me so long to raise this issue, or why it isn’t a hot topic. I’m sure you have all encountered this problem over the years. You’re following a tutorial on how to do something either with code, shortcodes, or something similar. You get to a code-formatted block, like so:
[formassembly formid=12345 server=”https://Yourserver.tld”]
You copy the shortcode into your project, and change the values. It doesn’t work. You bank your head into the wall, trying to figure it out. Finally, you realize that the quotes in the example have been converted to smart quotes!
In this example, the shortcodes were not in a code block. However, I have seen this problem every since the beginning of WordPress, all over the internet. There are countless tutorials on the web that have likely frustrated many a developer because there were converted characters in the code.
One solution is to make sure no quotes inside any code-related tags, like the <pre> tag, are ever converted to curlies. We can also make sure this is never triggered inside Gutenberg code blocks. Finally, we can update the curly quote logic so that it doesn’t trigger when surrounded by other characters that indicate it is part of code syntax, and not grammatical syntax.
- The topic ‘Curlies in code examples: the eternal curse of WordPress’ is closed to new replies.