Fixing Character Replacement in Wordpress

This has been bugging me for a while. But not enough to actually look into it. And Google searches for Wordpress display wrong characters results in a whole forest of threads about UTF-8 encoding. This has nothing to do with that. So what’s the issue here?

Wordpress is replacing characters in my posts. The most annoying being the replacement of – is with - . Which makes no sense at all. Specially when creating code samples. Or command line parameters. My thought is why on earth would you do that? But it probably has something to do with typography…

Anyways. Searching for it today made me stumble onto this post from 2007 by Paul Betts. And believe it or not. Wordpress is still doing that. The code has changed slightly tough. So i created a quick patch as a temporary solution. And need to figure out if this can be circumvented by a plugin or something. If that doesn’t exists already :)

The patch will replace the following lines

Original replacement arrays
$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 
);

With

Updated replacement arrays
$static_characters = $cockney;
$static_replacements = $cockneyreplace;
comments powered by Disqus