Summary: Add graphical smileys to the markup
Prerequisites: pmwiki-2.0.0
Categories: Images, Markup, Editing


smileys.zipΔ - complete zip archive including gif images
smileys.phpΔ - PHP code
smileys-V20050421.phpΔ - New PHP code, with few enhancements by CB


WikiSmileys allow graphical smileys to be inserted into documents. Markups such as :-) are converted to graphical images like happy smiley. The complete set of defined smileys are:

Enter markupto display this smiley
:) or :-) or {:) or {:-)happy smiley
;) or ;-) or {;) or {;-)winking smiley
:( or :-( or {:( or {:-(frowning smiley
:p or :-p or {:p or {:-plaughing smiley
:o or :-o or {:o or {:-oembarrassed smiley
:D or :-D or {:D or {:-Dgrinning smiley
{cool}cool smiley
{confused}confused smiley
{eek}shrieking smiley
{angry}angry smiley
{rolleyes}rolling eyes smiley


Unpack the smileys.zipΔ file into your pmwiki directory. The smileys.php file should go in your cookbook/ directory and the smiley images should go into pub/smileys/ (mind the pub/smileys directory attributes are 755 — else the image is not displayed, only the "alt" text). Then add the line


to your local/config.php file. That should do it for most installations. If you end up with broken images in the output instead of smileys, you may need to set the value of $SmileysFolder to be the URL prefix to where the smileys images are located. (Do this before loading the script with include_once.)

Add smiley buttons to the GUI buttons

You can add the smileys as buttons to the edit window, and have the smiley inserted with a click of the button. Add to config.php:

# smiley gui-edit buttons
$GUIButtons ['spacer7'] = array(700, '', '', '',
$GUIButtons['happy'] = array(710, ' \{happy\}', '', '',
$GUIButtons ['pixspace1'] = array(711, '', '', '',
$GUIButtons['wink'] = array(720, ' \{wink\}', '', '',
$GUIButtons ['pixspace2'] = array(721, '', '', '',
$GUIButtons['cool'] = array(730, ' \{cool\}', '', '',
$GUIButtons ['pixspace3'] = array(731, '', '', '',
$GUIButtons['confused'] = array(740, ' \{confused\}', '', '',
$GUIButtons ['pixspace4'] = array(741, '', '', '',
$GUIButtons['eek'] = array(750, ' \{eek\}', '', '',
$GUIButtons ['pixspace5'] = array(751, '', '', '',
$GUIButtons['rolleyes'] = array(760, ' \{rolleyes\}', '', '',
                  '$GUIButtonDirUrlFmt/rolleyes.gif"$[Roll eyes]"'); 
$GUIButtons ['pixspace6'] = array(761, '', '', '',
$GUIButtons['sad'] = array(770, ' \{sad\}', '', '',
$GUIButtons ['pixspace7'] = array(771, '', '', '',
$GUIButtons['mad'] = array(780, ' \{mad\}', '', '',
$GUIButtons ['pixspace8'] = array(781, '', '', '',
$GUIButtons['biggrin'] = array(790, ' \{biggrin\}', '', '',
                  '$GUIButtonDirUrlFmt/biggrin.gif"$[Big grin]"'); 

Copy the smiley images into pub/guiedit/.
Download Attach:pixspace.gifΔ and copy to pub/guiedit/.
This is used as a simple spacer between the smiley guibuttons.


  • Janice Heinold
  • Eike Decker (zet)
  • Pm
  • Klonk (modified for usage with PmWiki2)
  • CB
  • HansB

Comments, Bugs

How can one set a link to a "smiley"? [[{cool}->Cookbook.WikiSmileys]] does not work and results in {cool}. Any idea to make it run?. Armin
Add this markup to your smiley script, or config:

"Keep(\"<img src='".$SmileysFolder."/$1.gif' border='0' alt=' ' title=' ' class='smiley' />\")");

then you can use smileys of type {cool}, {eek}, etc, but not the others. Normal smiley markup is rendered much later than links, so that other markup is not ruined. - HansB October 13, 2009, at 06:42 AM

Thank you for the quick and competent answer! Armin P.S.: and of course: it works perfect.
  • Look at the source and you'll see how to add additional smileys to your markup. There are several sources on the net for images. Klonk
  • 06-Dec-2004 I fixed a bug that occured with numbered lists Klonk
  • 06-Dec-2004 I switched the script around so that smileys.php goes in the cookbook/ directory instead of local/. Pm
  • 18-Feb-2005 Fixed bug. Now valid XHTML code is produced Klonk
  • 08-Mar-2005 Few enhancements by CB. With this code, you can insert a smiley specifying its file name. Exemple : {003} will insert grinning smiley. It doesn't work on this server because this version (smileys-V20050308.php) is not installed. If you want, you can use this markup (:php_List_Smileys:) to list in a page all installed smileys (but beware, it can overload your web server) :
  function List_Smileys() {
  1. Open the directory containing the smileys
  $dir = "name/of/the/directory"; // or $SmileysFolder if global
  $pattern = '/(.*)\.gif/';
  $source = "";
  if (is_dir($dir)) {
     if ($dh = opendir($dir)) {
         while (($file = readdir($dh)) !== false) {
		   if (preg_match($pattern, $file, $matches)) {
		     $source = $source . sprintf("{%s}", $matches[1]);
         return $source;
  Markup('php_List_Smileys', 'directives', '/\\(:php_List_Smileys:\\)/e', "List_Smileys()");
  • 21-April-2005 Bugs correction by CB
  • 07-Jul-2005 Changed original version. It now requires one or more space characters before the smiley. This should fix some displaying issues. Klonk
  • 11-Oct-2005 Needs minor modification in smileys.php to work with WikiFarms .
    $SmileysFolder = "$FarmPubDirUrl/smileys";
    SDV($FarmPubDirUrl, $PubDirUrl);
    $SmileysFolder = "$FarmPubDirUrl/smileys";

    Then the usual $FarmD include path modification with include_once("$FarmD/cookbook/smileys.php"); will work. --GToye
  • 05-Nov-2005: It seems that :) for some reason doesn't work on my page, while :-) does. As as user service on my page, I therefore added the smileys as $GUIButtons['happy'] = array(620, ':-)', '', '', '$GUIButtonDirUrlFmt/happy.gif"$[Happy]"'); in the config.php. Works great and my users seem to like it better than to have to type :-). I have copies of the smileys both in guiedit and smileys dir now, though, but if it ain't broken, don't fix it... Jakob Mark?


  • 30-Mar-2005 I just found a problem with (:loginform:) because of the bracket at the end. This kind of markup does not function. I just modified the code to "/\s+{?:-?\)/"," but I am still a newbie in PHP. Please check it. winking smiley (Holger)
  • Even if I set $SmileysFolder to point to local/smilies/ it searches for the smilies in pub/smileys/ (Petra)
    You have to set $SmileysFolder before including the script. --Pm
  • 1-Apr-2005 I figured out one way of fixing the interaction of smileys and comments, which is to require a "nose", i.e. a - sign, between the eyes and grin of the standard smiley, i.e. :) doesn't work, but :-) does. To do that, replace /\{?:-?\)/ with /\{?:-\)/. - David A. Spitzley
  • 20-Apr-2005 I found a random sorting of the Markups, because everything went to the "block" section. If the CB extension is used and the "icon" markup is randomly first, the {angry} smiley wasn't shown, because the icon is "mad.gif". I changed all markup except icon from "block" to "<icon" and this will avoid this behaviour. I didn't check any other problems with this new markup sorting. Henry
  • 21-April-2005 Corrected I hope with the new version (20050421) CB
  • I found a problem: I pasted the smileys table above to one of my wiki pages as a documentation. It works only in preview mode, not when the page is saved (shows the code). smileys in normal text are displayed correct. (Stephan)
  • 25-May-2011 The smileys alone in a table cell do not work for me || :D || , although they do work like this: || test: :D || . Any idea how to make it work in empty cells? (a non-breaking space did not seem to help.) Thanks, Jonne.