How to avoid that wordpress replaces — with – in HTML

Wednesday, August 5, 2009 posted by Till

If you run a blog that covers topics from Linux / Unix like we here at FAQforge and you include Linux shell commands in a wordpress post, you might have noticed that WordPress replaces the char combination "--" with – in the HTML sources. But the replacement – is displayed by the browser as "-" and not "--". So if someone copys your shell command examples to execute them, they will not work. To fix this behaviour, edit the file wp-includes/formatting.php in wordpress and replace the lines 55 and 56:

$static_characters = array_merge(array('---', ' -- ', '--', ' - ', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
$static_replacements = array_merge(array('—', ' — ', '–', ' – ', 'xn--', '…', $opening_quote, '’s', $closing_quote, ' ™'), $cockneyreplace);

with:

$static_characters = array_merge(array('---', ' -- ', 'xn–', '...', '``', '\'s', '\'\'', ' (tm)'), $cockney);
$static_replacements = array_merge(array('—', ' — ', 'xn--', '…', $opening_quote, '’s', $closing_quote, ' ™'), $cockneyreplace);

Be Sociable, Share!



One Response to “How to avoid that wordpress replaces — with – in HTML”

  1. John McGrath says:

    This can be also be an issue for anyone trying to post a flash object in wordpress using valid xhtml like…

    <!–

    Missingflash content.

    <!- <![endif]–>

    This fails in wordpress because of the wrong rendering of ‘-‘ and this solution solves the problem perfectly.

    Brilliant! Thanks

Leave a Reply