Removing curly quotes from WordPress 2.1.*

A while ago I wrote a post on preventing the curlification of the quotes on WordPress. This is useful when you run something like a code-sharing site, and each string variable gets encoded with unusable fancy quotes. mhinze.com recently shared the solution for removing curly quotes on WordPress 2.1, but it actually might do a bit more than you expect.

In your Wordpress folder go for the wp-includes folder and find a file called formatting.php. Lines 20 and 21 look like:


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

The arrays contain characters to find and characters to replace. There’s one to one correspondence. As you can see, a double dash, a triple dash and a double dash with spaces get replaced by an em dash. The ellipsis gets replaced by …

The characters in question are ‘\’\”‘ – backslash-escaped (since PHP requires it) single quote and double quote replaced by ” Remove both ‘\’\”‘ from static_characters array and ” from static_replacements array, and you’re good to go – you will still keep your ellipsis, your em dashes, and your trademark symbols.

Tip 1: this will still leave the fancy quotes for backticks (those ` characters to the left of 1 on your keyboard) and fancy apostrophe in the possessive ’s, like “This is Alex’s site”. If you want those removed as well, remove elements ‘“’, ‘\’s’ from static_characters and corresponding values ‘“’, ‘’s’ from static_replacements.

Tip 2: Want some other character replaced automatically? Then insert a character to replace into static_characters, such as (c) and insert a character into static_replacements, such as ©

Posted Thursday, March 15th, 2007 under PHP, Programming, WordPress.

2 comments

  1. i think the static_characters array is quite valuable. it allows you to inject those special curly double quotes at will – but won’t stop wordpress from converting actual quotation marks ”

    the dynamic characters array is where you want to make your change

  2. Спасибо, Алекс, это лучшее решение, чем отрубать весь типограф )

Leave a Reply