Compdigitec Labs

« | Home | »

Disable WordPress conversion of double-dashes in posts

By admin | July 24, 2009

Update (2014-08-09): Still works for WordPress 3.9.2.

Update (2013-11-16): Still works for WordPress 3.7.1.

Update (2012-07-26): Updated for WordPress 3.4.1.

Update (2012-02-03): Updated for WordPress 3.3.1.

Update (2011-08-21): Updated for WordPress 3.2.1.

Update (2009-08-16): Updated for WordPress 2.8.3.

If you use WordPress (like this blog and many hundreds and thousands of blogs) for your blogging engine and you attempt to post code or programming related posts, you may find that WordPress will mess up your code. This was pointed out to us by a commenter on the aforementioned page. Out of the side, the guide at Tech-Recepies will not work as the mentioned line of code no longer exists in WordPress.

This guide has been tested with WordPress 2.7.1, 2.8.3, 3.3.1, 3.4.1, 3.5, 3.7.1, and 3.9.2 (latest).

WordPress 3.9.2, 3.7.1, 3.5, and 3.4.1
Apply this diff to wp-includes/formatting.php like so:

patch formatting.php formatting.diff

Manual patching: replace lines 73 and 74 of “wp-includes/formatting.php” with these two lines:

		$static_characters = array_merge( array( /*'---', ' -- ', '--', ' - ', 'xn–',*/ '...', '``', '\'\'', ' (tm)' ), $cockney );
		$static_replacements = array_merge( array( /*$em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--', */'…', $opening_quote, $closing_quote, ' ™' ), $cockneyreplace );

WordPress 3.3.1
Apply this diff to wp-includes/formatting.php like so:

patch formatting.php formatting.diff

Manual patching: replace lines 56 and 57 of “wp-includes/formatting.php” with these two lines:

		$static_characters = array_merge( array(/*'---', ' -- ', '--', ' - ', 'xn–',*/ '...', '``', '\'\'', ' (tm)'), $cockney );
		$static_replacements = array_merge( array(/*$em_dash, ' ' . $em_dash . ' ', $en_dash, ' ' . $en_dash . ' ', 'xn--',*/ '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace );

WordPress 3.2.1
You can apply this diff to wp-includes/formatting.php like so:

patch formatting.php formatting.diff

Or you can patch it manually with the following directions:

  1. Download <blog path here>/wp-includes/formatting.php from your webserver (using something like FTP or SSH). Don’t navigate to the page and try to use “Save Page As”, it won’t work.
  2. Open formatting.php with a text editor, preferably with the ability to navigate to specific lines (such as Geany, which also displays the line numbers beside each line).
  3. Go to line 52/53 and find this:
  4. $static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)'), $cockney);
    $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace);
    
  5. Replace it with this:
    $static_characters = array_merge(array(/*'---', ' -- ', '--', ' - ', 'xn–',*/ '...', '``', '\'\'', ' (tm)'), $cockney);
    $static_replacements = array_merge(array(/*'—', ' — ', '–', ' – ', 'xn--',*/ '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace);
    
  6. Save and re-upload to web server.

Instructions (2.x)

  1. Download <blog path here>/wp-includes/formatting.php from your webserver (using something like FTP or SSH). Don’t navigate to the page and try to use “Save Page As”, it won’t work.
  2. Open formatting.php with a text editor, preferably with the ability to navigate to specific lines (such as Geany, which also displays the line numbers beside each line).
  3. (2.7.1 only)
  4. Navigate/browse to line 47/48 and find the following code:
  5. $static_characters = array_merge(array(‘---’, ‘ -- ‘, ‘--’, ‘xn&#8211;’,‘…’, ‘“’, ‘\’s’, ‘\’\”, ‘ (tm)’), $cockney);
    $static_replacements = array_merge(array(‘&#8212;’, ‘ &#8212; ‘, ‘&#8211;’, ‘xn--’,‘&#8230;’, ‘&#8220;’, ‘&#8217;s’, ‘&#8221;’, ‘ &#8482;’), $cockneyreplace);
  6. (2.8.3 only)
  7. Browse to line 55/56 and find the following code:

  8. $static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn&#8211;', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
    $static_replacements = array_merge(array('&#8212;', ' &#8212; ', '&#8211;', ' &#8211; ', 'xn--', '&#8230;', $opening_quote, '&#8217;s', $closing_quote, ' &#8482;'), $cockneyreplace);


  9. (end version specific instructions)
  10. Once you have found the aforementioned lines of code, comment out the first four items in each array. In short, replace the above two lines with:
  11. (2.7.1 only)
  12. $static_characters = array_merge(array(/*’---’, ‘ -- ‘, ‘--’, ‘xn&#8211;’,*/‘…’, ‘“’, ‘\’s’, ‘\’\”, ‘ (tm)’), $cockney);
    $static_replacements = array_merge(array(/*’&#8212;’, ‘ &#8212; ‘, ‘&#8211;’, ‘xn--’,*/‘&#8230;’, ‘&#8220;’, ‘&#8217;s’, ‘&#8221;’, ‘ &#8482;’), $cockneyreplace);
  13. 2.8.3 only

  14. $static_characters = array_merge(array(/*'---', ' -- ', '--', ' - ', 'xn&#8211;',*/ '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
    $static_replacements = array_merge(array(/*'&#8212;', ' &#8212; ', '&#8211;', ' &#8211; ', 'xn--',*/ '&#8230;', $opening_quote, '&#8217;s', $closing_quote, ' &#8482;'), $cockneyreplace);


  15. (end version specific instructions)
  16. Save the file and re-upload to take effect.

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: (X)HTML, HTTP (Internet) | 6 Comments »

6 Responses to “Disable WordPress conversion of double-dashes in posts”

  1. oyunlar1 Says:
    August 5th, 2009 at 3:20 am

    thanks so much…
    it works for “…” =)

  2. Ari Says:
    August 13th, 2009 at 7:37 am

    Thanks! Just upgrading wordpress reverts this stupid behaviour, I don’t see why they wouldn’t make this more easily configurable.
    I really should keep this post bookmarked, it’s not fun searching for it every single time I upgrade my wordpress.

  3. Tim Says:
    October 11th, 2009 at 8:51 pm

    This works well for guitar tab which uses hyphens / dashes everywhere. Thanks for this.

  4. black hattitude Says:
    October 31st, 2009 at 6:20 am

    Hi,

    Thank you for the great quality of your blog, each time i come here, i’m amazed.

    black hattitude.

  5. Pareen Says:
    August 25th, 2010 at 11:35 pm

    Hi,

    Thank you for a great article.

    All got replaced except ‘ single quote is still being shown as ’s

    Please, can you help?

  6. Carlo @ MMA Acupuncture Says:
    July 14th, 2012 at 9:09 pm

    Thanks 10x for the fix! Seemed to work for WordPress 3.4

Comments