« 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, HTTP (Internet) | 27 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
February 14th, 2022 at 13:35
… [Trackback]
[…] Read More on on that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
April 9th, 2022 at 03:26
… [Trackback]
[…] Find More Info here to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
April 14th, 2022 at 19:18
… [Trackback]
[…] Read More to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
May 16th, 2022 at 18:50
… [Trackback]
[…] Info to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
May 23rd, 2022 at 12:52
… [Trackback]
[…] Info to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
July 17th, 2022 at 18:29
… [Trackback]
[…] Read More to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
August 18th, 2022 at 18:54
… [Trackback]
[…] Find More Info here to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
October 13th, 2022 at 21:16
… [Trackback]
[…] Find More Information here to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
October 30th, 2022 at 13:56
… [Trackback]
[…] Find More to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
November 2nd, 2022 at 00:31
… [Trackback]
[…] Find More to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
November 26th, 2022 at 02:09
… [Trackback]
[…] Find More here on that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
December 3rd, 2022 at 00:15
… [Trackback]
[…] Read More Information here on that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
December 17th, 2022 at 10:36
… [Trackback]
[…] Information to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
January 7th, 2023 at 01:04
… [Trackback]
[…] Find More on that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
January 9th, 2023 at 17:28
… [Trackback]
[…] Find More Information here on that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
January 19th, 2023 at 14:09
… [Trackback]
[…] Find More on on that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
January 24th, 2023 at 11:27
… [Trackback]
[…] Here you can find 40886 additional Info to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
January 27th, 2023 at 03:40
… [Trackback]
[…] Find More to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
January 28th, 2023 at 01:48
… [Trackback]
[…] Read More Information here on that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
January 29th, 2023 at 19:57
… [Trackback]
[…] Here you will find 78465 additional Info on that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]
February 3rd, 2023 at 14:07
… [Trackback]
[…] Read More to that Topic: compdigitec.com/labs/2009/07/24/disable-wordpress-conversion-of-double-dashes-in-posts/ […]