Hack: Stop WordPress From Curling Your Quotes

I recently posted a quick little bit of JavaScript on my MacMost site in a comment. It should have been quick copy and paste solution to a user’s problem. But instead they got an error message.

The problem was the line of code I posted used some quotes. WordPress tried to be helpful and converted them to smart quotes, which broke the code.

There are two solutions for this. I could have anticipated this problem and enclosed the line in a <code> tag. But I didn’t notice the problem until it was too late.

The other solution is to turn off the wptexturize filter that WordPress is running all text through. This not only prevents changing quotes, but also some other character conversions that will break code. You can put this in your theme’s function.php file or you own custom plugin.

remove_filter('the_content', 'wptexturize');

You can check out the details of what wptexturize does at the official Codex page. It would be great to just disable a few of these. I suppose if you really wanted to you could disable wptexturize and enable a function of your own making that changes what you want.

Leave a Reply

Your email address will not be published. Required fields are marked *