Fix WordPress’ Over-zealous XHTML Compliance Interfering With wp-syntax
Over the last few days, I’ve noticed that WordPress started converting all of the special HTML characters into their proper HTML entities (ei: & will be translated into &), even though I explicitly specified that I do want the character itself. This interfered with the wp-syntax plugin that I use when I post snippets of code, because the plugin assumes that non-HTML encoded code is being used. It applied the conversion to HTML entities after all that is done. But now because of WordPress’ over-zealous compliance to XHTML specs, when the following is part of a post:
<pre lang=”php”>if(true && false) echo “Hello World”;</pre>
You will see the following:
if(true && false) echo "Hello World"; |
Luckily, the fix is quite simple. It does not even involve using the seemingly abandoned role-manager plugin as suggested by wp-syntax’s FAQ. Just add the escaped=”true” argument to the pre tag, and wp-syntax will decode the HTML entities for you automatically. Now
<pre lang=”php” escaped=”true”>if(true && false) echo “Hello World”;</pre>
turns into
if(true && false) echo "Hello World"; |
To make things easier, I suggest that you install the wp-syntax-button plugin. This plugin adds a “Code” button to the visual WordPress editor, using which you can automatically highlight any code without having to switch to the HTML editor. And of course, the wp-syntax-button plugin automatically adds the escaped=”true” argument.
Hopefully you kept a backup copy of WordPress on your computer?Otherwise, see if your hosting provider has a backup that you can recover to.