WordPress 3.3: Stop replacing double dashes and single quotes

Want to help support this blog? Try out Oh Dear, the best all-in-one monitoring tool for your entire website, co-founded by me (the guy that wrote this blogpost). Start with a 10-day trial, no strings attached.

We offer uptime monitoring, SSL checks, broken links checking, performance & cronjob monitoring, branded status pages & so much more. Try us out today!

Profile image of Mattias Geniar

Mattias Geniar, January 03, 2012

Follow me on Twitter as @mattiasgeniar

Oh boy, another update to WordPress, another set of changes to the WordPress core to prevent WordPress from changing the default double dash and single quote characters to the “pretty” HTML versions &#8217, &#8216, &#8211, &#8212, …

When posting snippets of source code or command line arguments, having the quotes and dashes replaced makes copy/pasting the commands a pain, as your terminal won’t recognise them.

So, if you want to fix that in WordPress 3.3, edit the /wp-includes/formatting.php file and go to around line 61. You’ll see something like this.

function wptexturize($text) {
....
$static_characters = array_merge(...
$static_replacements = array_merge(...
$dynamic_characters = array(...
$dynamic_replacements = array(...
...
}

Right below those 4 PHP variables, add the following lines.

// Just ignore everything from above
$static_characters = array();
$static_replacements = array();
$dynamic_characters = array();
$dynamic_replacements = array();

That simply overwrites whatever WordPress had defined to be replaced, to leave it at the default HTML characters.

If you’ve done that above, the file should look similar to the screenshot below.

And afterwards, the dashes shouldn’t be replaced anymore!



Want to subscribe to the cron.weekly newsletter?

I write a weekly-ish newsletter on Linux, open source & webdevelopment called cron.weekly.

It features the latest news, guides & tutorials and new open source projects. You can sign up via email below.

No spam. Just some good, practical Linux & open source content.