WordPress Smilies Cleanup

Posted in: WordPress

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]

Popularity: 6% [?]

Posted January 23rd, 2007 @ 5:32 PM

11 Replies

  1. Rirath adds this Comment:

    Interesting, that does indeed explain a thing or two.

    January 23rd, 2007 at 9:03 pm

  2. Les adds this Comment:

    I had some fun with that while testing 2.1. I used the Search and replace plugin rather than working directly with MySQL. I also modified WP-Grins to make sure to pad spaces around new smilies - documented here.

    January 24th, 2007 at 1:50 am

  3. Emu adds this Comment:

    To “fix” Smilies in Wordpress 2.1 just line:
    $wp_smiliessearch[] = '/(\s|^)'.preg_quote($smiley, '/').'(\s|$)/';
    in /wp-includes/vars.php with
    $wp_smiliessearch[] = '/(\s|^)'.preg_quote($smiley, '/').'/';

    Regards Emu

    January 24th, 2007 at 7:41 am

  4. Alex adds this Comment:

    Simple, yes - but when you end up with a dozen or so of those little tweaks to be done on each upgrade, it’s a hassle. Making my data comply with WordPress’ expectations is a better forward-looking solution.

    January 24th, 2007 at 10:02 am

  5. Emu adds this Comment:

    You are right, Alex.

    I know this disadvantage well but I post that solution for people that do not want to edit his post and database records.

    I’ll try to write a plugin that make this changes on the fly, so if the Wordpress developers do not change the regular expression in next versions, this “fix” to work. If I success with develop, I’ll post here again.

    Regards Emu

    P.S. Sorry for my not so good english.

    January 24th, 2007 at 5:41 pm

  6. David adds this Comment:

    Where the behavior is most annoying is in comments. Average folk are more likely to use colon-parenthesis symbols which WordPress won’t replace correctly “on the fly” unless someone happens to luck into the secret method. I don’t get so many smiley-laced comments that’s it’s actually a problem for me, but it did happen often enough to drive me to the codex and help forums to see if it was just me…

    January 24th, 2007 at 6:56 pm

  7. Emu adds this Comment:

    How I promise, I write here again ;).

    I wrote a plugin that “fix” wordpress 2.1 smilies. If someone want it - Usmivki.

    Regards Emu

    January 26th, 2007 at 12:50 am

  8. Mark adds this Comment:

    But what about smilies that have not a space in front of them? They are still being parsed as text instead of smilies….

    February 6th, 2007 at 10:57 am

  9. Mark adds this Comment:

    e.g. say that :cheese: is a smilie.

    :cheese::cheese::cheese::cheese:

    will only give

    [smilie]:cheese::cheese::cheese:

    February 6th, 2007 at 11:11 am

  10. 加入表情符號(2.1版以後) adds this Pingback:

    […] smiles Cleanup|alexking […]

    August 7th, 2007 at 10:27 am

  11. wp-grins插入表情(2.1以後) adds this Pingback:

    […] smiles Cleanup|alexking […]

    January 26th, 2008 at 10:00 am

Add a Comment

Please note: Use of a non-personal web site or blog in the field below and/or comments that are off-topic, personal attacks, or support requests will likely be removed at my discretion.

Note: This post is over a year and a half old. You may want to check later in this blog to see if there is new information relevant to your comment.

Can I start a movement? » « Wii

About This Site

This is the personal web site of Alex King, a web developer in Denver, Colorado USA. More...


Crowd Favorite

Crowd Favorite is my software and web development business.

We build web applications, design and develop custom WordPress themes and plugins, and build custom sites using WordPress as a CMS.


I also have a tumblog that aggregates my online content from other services (Twitter, Flickr, del.icio.us. etc.).

I'm voting for Barack Obama

Ads