WordPress v3.1, v3.2: Don’t Replace (Double & Single) Dashes & (Double & Single) Quotes!

Mattias Geniar, Monday, August 23, 2010 - last modified: Tuesday, January 3, 2012

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/<themename>/ 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.



Hi! My name is Mattias Geniar. I'm a Support Manager at Nucleus Hosting in Belgium, a general web geek & public speaker. Currently working on DNS Spy & Oh Dear!. Follow me on Twitter as @mattiasgeniar.

Share this post

Did you like this post? Will you help me share it on social media? Thanks!

Comments

Jared Thursday, October 28, 2010 at 22:24 - Reply

Thanks. That was very helpful!


BadBoyFromTheRai Saturday, December 3, 2011 at 00:57 - Reply

Давно эта тема не поднималась)
Смотрю народ оживился


Leave a Reply

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

Inbound links