WordPress Smilies Cleanup

Somewhere along the way, it seems that WordPress started requiring a space or line break after a smiley key in order for the key to be properly replaced with the smiley image.

For example:

:lol: , said the hyena.

instead of:

:lol:, said the hyena.

The first has a space after the ": l o l :" key, where the second does not.

I probably could have dug through the WP code and found where to change this, but the new behavior doesn't really bother me and I only had a couple of places where I needed to fix this.

Here is sample SQL1 to see if you have places in your database that need fixing:

SELECT *
FROM wp_posts
WHERE post_content LIKE '%:,%'
SELECT *
FROM wp_posts
WHERE post_content LIKE '%:,%'

etc.

And here is the SQL to fix it:

UPDATE wp_posts
SET post_content =
REPLACE(post_content, ':,', ': ,');
UPDATE wp_posts
SET post_content =
REPLACE(post_content, ':.', ': .');

etc.

Of course, you want to make sure you back up your database first before making sweeping changes like this. I screwed up the syntax myself and had to restore my posts table from my nightly backup.

It happens. 🙂

  1. This all assumes the standard 'wp_' prefix for your database tables. [back]