How to avoid that wordpress replaces — with – in HTML

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);

facebooktwittergoogle_plusredditlinkedinmail

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

  1. 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

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>