Whilst monitoring the #wordpress irc channel on irc.freenode.net I came across a question by “erchik” asking how to add smilies to his widgets.
After some researching I found this to be quite simple, of course there is unfortunately no global way of doing this for all your widgets at once, since every widget has it’s own backend, but it’s quite easy to achieve and is not limited to widgets, you can use it in plugins and templates all the same.
Simply add the following lines to your code right before you are outputting the string that you want to contain smilies
global $wp_smiliessearch, $wp_smiliesreplace; $content = preg_replace($wp_smiliessearch, $wp_smiliesreplace, $content);
Replace $content with the name of your string containing the content.
If for whatever reason this does not work for you, try adding the following line before the 2 lines given:
smilies_init();
This will populate the smilie replacement vars.
And that’s it, in this case I was applying it to a widget called MiniPosts (version 0.6.6), you can get the patch file for it here (right click > save as).
To apply the patch on a linux box simply execute the following command
patch -i /path/to/miniposts2.php.patch /path/to/miniposts2.php
Basically what you need to do is add the following 2 lines at line 424 of miniposts2.php
global $wp_smiliessearch, $wp_smiliesreplace; $text = preg_replace($wp_smiliessearch, $wp_smiliesreplace, $text);
I’d drop the modified miniposts2.php file here but I don’t feel comfortable posting / hosting somebody elses work, I’ll contact the author though.


Thank you very much! Works just fine!
[...] updated miniposts to look nice in Wordpress 2.7. I’ve also included naatan’s smiley goop. Go download 0.6.7 now! (Or wait until Wordpress.org lets me host it in their [...]
[...] issues, cleans up the preferences page, and fixes a couple of bugs with the smiley code that nataan [...]