« Installing sound drivers for VirtualBox sound in Windows 7 | Home | Solving “Fatal error: Exception thrown without a stack frame in Unknown on line 0” »
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:
- 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.
- 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).
- Go to line 52/53 and find this:
-
$static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'\'', ' (tm)'), $cockney); $static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace);
- Replace it with this:
$static_characters = array_merge(array(/*'---', ' -- ', '--', ' - ', 'xn–',*/ '...', '``', '\'\'', ' (tm)'), $cockney); $static_replacements = array_merge(array(/*'—', ' — ', '–', ' – ', 'xn--',*/ '…', $opening_quote, $closing_quote, ' ™'), $cockneyreplace);
- Save and re-upload to web server.
Instructions (2.x)
- 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.
- 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).
- (2.7.1 only)
- Navigate/browse to line 47/48 and find the following code:
- $static_characters = array_merge(array(‘—‘, ‘ — ‘, ‘–‘, ‘xn–’,‘…’, ‘“’, ‘\’s’, ‘\’\”, ‘ (tm)’), $cockney);
$static_replacements = array_merge(array(‘—’, ‘ — ‘, ‘–’, ‘xn--‘,‘…’, ‘“’, ‘’s’, ‘”’, ‘ ™’), $cockneyreplace); - (2.8.3 only)
- Browse to line 55/56 and find the following code:
$static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
$static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, '’s', $closing_quote, ' ™'), $cockneyreplace);
- (end version specific instructions)
- 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:
- (2.7.1 only)
- $static_characters = array_merge(array(/*’—‘, ‘ — ‘, ‘–‘, ‘xn–’,*/‘…’, ‘“’, ‘\’s’, ‘\’\”, ‘ (tm)’), $cockney);
$static_replacements = array_merge(array(/*’—’, ‘ — ‘, ‘–’, ‘xn--‘,*/‘…’, ‘“’, ‘’s’, ‘”’, ‘ ™’), $cockneyreplace); - (2.8.3 only)
$static_characters = array_merge(array(/*'---', ' -- ', '--', ' - ', 'xn–',*/ '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
$static_replacements = array_merge(array(/*'—', ' — ', '–', ' – ', 'xn--',*/ '…', $opening_quote, '’s', $closing_quote, ' ™'), $cockneyreplace);
- (end version specific instructions)
- 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, Internet | 10 Comments »
August 5th, 2009 at 03:20
thanks so much…
it works for “…” =)
August 13th, 2009 at 07:37
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.
October 11th, 2009 at 20:51
This works well for guitar tab which uses hyphens / dashes everywhere. Thanks for this.
October 31st, 2009 at 06:20
Hi,
Thank you for the great quality of your blog, each time i come here, i’m amazed.
black hattitude.
August 25th, 2010 at 23:35
Hi,
Thank you for a great article.
All got replaced except ‘ single quote is still being shown as ’s
Please, can you help?
July 14th, 2012 at 21:09
Thanks 10x for the fix! Seemed to work for WordPress 3.4
November 19th, 2024 at 01:45
… [Trackback]
[…] Read More on to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
November 23rd, 2024 at 08:55
… [Trackback]
[…] Here you can find 67890 more Info to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
December 2nd, 2024 at 20:58
… [Trackback]
[…] There you will find 64587 more Info on that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
December 17th, 2024 at 07:32
… [Trackback]
[…] Here you will find 12970 more Info to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]