WordPress v3.1, v3.2: Don’t Replace (Double & Single) Dashes & (Double & 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, August 23, 2010

Follow me on Twitter as @mattiasgeniar

WordPress has a built-in feature that will replace a double dash (noted as “–") with a single, but slighly longer, dash. This is great if you’re a writer or reporter, but it’s damn annoying if you’re trying to write Linux commands, or any other form of code, where you need the -– characters to remain in place. The same applies to quotes (single ' or double “), being replaced with more stylish forward ticks.

So, let’s fix that.

Update: If you’re having troubles replacing the double quotes with WordPress 3.3, have a look here: WordPress 3.3 stop replacing double quotes and single dashes.

****Open up /wp-includes/formatting.php and find the lines around 56 and 57 (this will vary depending on your WordPress version), which start with:

$static_characters = array_merge(array('-–', ' -– ‘, ‘–', ' – ‘, …

$static_replacements = array_merge(array('—', ' — ‘, ‘–', ' – ‘, …

These lines effectively translate your double dashes (–) to the HTML character of a single dash. Remove the third element from every array there, so it looks something like this (please note the line continues, so just remove only the 3rd element from each array).

$static_characters = array_merge(array('-–', ' -– ‘, ' – ‘, …

$static_replacements = array_merge(array('—', ' — ‘, ' – ‘, …

You can now happily write double dashes again!

# ./fix_wordpress.sh –without-silly-dashes –with-something-else

If you want to prevent the single & double quotes as being replaced automatically, open up your functions.php file in your /wp-includes/themes// folder. Create the file if doesn’t exist. And add the following line of code all the way at the bottom.

# Custom: remove (single & double) quote replacements in posts

remove_filter(‘the_content’, ‘wptexturize’);

This will remove the filter defined in WordPress, so it will no longer replace your single & double quotes.



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.