Posted by & filed under General, MySQL, PHP.

(Updated October 2012)

WordPress has long had a feature that dynamically replaces standard characters with their more visually appealing (and perhaps more accurate) symbols. In some cases the formatting may not be desirable.

Last year I wrote a few articles on Exchange Server errors. The errors typically follow the form of 0xNumber, ex. 0x8000000F. What wordpress was doing was replacing the “x” in the error with a “times” or multiplication symbol. So 0x0 would show up as 0×0.

Dynamic Replace Active

Dynamic Replace Inactive

My concern was that search engines DO distinguish between “x” and the symbol for multiplication. So when people were searching for 0x8004011D my posts did not show up, but when searching for 0×8004011D or 8004011D they did. If you do a google search with the “times” symbol instead of an “x” for exchange errors, you will find many posts otherwise hidden from the world.

The last string of the regular expression below represents a case for when there is a character followed by an x and by another character without spaces. The x will be replaced with the special character for “times” or &# 215 ;

The characters in the image below are the symbols for replacement. Generally the quotes are not misleading to search engines.

WordPress 3.3.x and Earlier

The following dynamic string variable is found in the \wp-includes\formatting.php file. If you wish to remove all dynamic characters, simply delete both lines and your wordpress posts will render correctly.

$dynamic_characters = array
('/\'(\d\d(?:’|\')?s)/', '/(\s|\A|")\'/', 
'/(\d+)"/', '/(\d+)\'/', '/(\S)\'([^\'\s])/', '/(\s|\A)"(?!\s)/', 
'/"(\s|\S|\Z)/', '/\'([\s.]|\Z)/', '/(\d+)x(\d+)/');

 $dynamic_replacements = array
('’$1','$1‘', '$1″', 
'$1′', '$1’$2', '$1“$2', 
'”$1', '’$1', '$1×$2');

If you only want to remove the “x” replacement symbol ( × ) use the following lines in formatting.php in place of the originals.

$dynamic_characters = array(‘/\’(\d\d(?:’|\’)?s)/’, ‘/(\s|\A|”)\’/’,’/(\d+)”/’, ‘/(\d+)\’/’, ‘/(\S)\’([^\'\s])/’, ‘/(\s|\A)”(?!\s)/’,’/”(\s|\S|\Z)/’, ‘/\’([\s.]|\Z)/’);

$dynamic_replacements = array(‘’$1′,’$1‘’, ‘$1″’, ‘$1′’, ‘$1’$2′, ‘$1“$2′, ‘”$1′, ‘’$1′);


WordPress 3.4.x and Later

Delete the following line in \wp-includes\formatting.php to remove the “x” replacement symbol ( × ) (times) between numbers.

$dynamic[ '/\b(\d+)x(\d+)\b/'              ] = ‘$1×$2′; // 9x9 (times)
(5.00 out of 5)

3 Responses to “WordPress Dynamic Replacement”

  1. Ferodynamics

    I’m wondering why they’re called “dynamic” characters? It’s not like they’re moving ;-)

    Also, I’m wondering what’s the original reason for these replacements. Strictly cosmetic?

    • Chris Stinson

      The quotes were cosmetic.

      The “x” replacement is a proper symbol for multiplication – and since it is only replaced when an “x” occurs between two numbers, it makes sense. A notable exception is typical computer error codes where the symbol is indeed meant to be an “x” between two numbers.

      I think for most people dynamic replacement is a good idea.

      Oh, and I know you were joking about the name “dynamic,” but for anyone who doesn’t know why, it’s because when the PHP script is parsed, it loads the special symbols instead of the original text stored in the database. This happens every time a wordpress page is called. Dynamic pages like this increase server load. I’d recommend WP-Cache to reduce the load for popular sites.



  1.  WPscoop | Wordpress Social News and Bookmarking

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=""> <strike> <strong>