Make WordPress Stop Replacing Double Dash with Em-dash

Posted November 20, 2006 by johnnythawte in PHP programming

WordPress by default replaces the double dash (–) with an em-dash character. If you are showing code or programming examples this will cause your visitors unnecessary confusion. This recipe shows the simple way to turn that behavior off.


This problem is occurring because WordPress automatically runs a bunch of filters on your content before displaying it out to the browser. These filters include the smiley face replacement and others to try and clean up the content and make it more presentable to users. We will leave the rest of the filters alone.

Start by using either your ftp, ssh, or other client to open up the SITE_ROOT/wp-includes/functions-formatting.php file in a text editor and find these two lines:
$curl = str_replace(’ -- ‘, ‘ — ‘, $curl);
$curl = str_replace(’--’, ‘–’, $curl);

You can comment out these lines by putting the php // comment characters before them both, or you could simply delete the lines. When you are done, it should look like this:
//$curl = str_replace(’ -- ‘, ‘ — ‘, $curl);
//$curl = str_replace(’--’, ‘–’, $curl);

Now you will be able to see the double dash character in your blog posts, and no more comments from upset visitors saying that your examples aren’t working. =)

The Conversation

Follow the reactions below and share your own thoughts.