Title: smilies_init
Published: April 25, 2014
Last modified: May 20, 2026

---

# smilies_init()

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#description)
 * [Source](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#wp--skip-link--target)

Converts smiley code to the icon graphic file equivalent.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#description)󠁿

You can turn off smilies, by going to the write setting screen and unchecking the
box, or by setting ‘use_smilies’ option to false or removing the option.

Plugins may override the default smiley list by setting the $wpsmiliestrans to an
array, with the key the code the blogger types in and the value the image file.

The $wp_smiliessearch global is for the regular expression and is set each time 
the function is called.

The full list of smilies can be found in the function and won’t be listed in the
description. Probably should create a Codex page for it, so that it is available.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#source)󠁿

    ```php
    function smilies_init() {
    	global $wpsmiliestrans, $wp_smiliessearch;

    	// Don't bother setting up smilies if they are disabled.
    	if ( ! get_option( 'use_smilies' ) ) {
    		return;
    	}

    	if ( ! isset( $wpsmiliestrans ) ) {
    		$wpsmiliestrans = array(
    			':mrgreen:' => 'mrgreen.png',
    			':neutral:' => "\xf0\x9f\x98\x90",
    			':twisted:' => "\xf0\x9f\x98\x88",
    			':arrow:'   => "\xe2\x9e\xa1",
    			':shock:'   => "\xf0\x9f\x98\xaf",
    			':smile:'   => "\xf0\x9f\x99\x82",
    			':???:'     => "\xf0\x9f\x98\x95",
    			':cool:'    => "\xf0\x9f\x98\x8e",
    			':evil:'    => "\xf0\x9f\x91\xbf",
    			':grin:'    => "\xf0\x9f\x98\x80",
    			':idea:'    => "\xf0\x9f\x92\xa1",
    			':oops:'    => "\xf0\x9f\x98\xb3",
    			':razz:'    => "\xf0\x9f\x98\x9b",
    			':roll:'    => "\xf0\x9f\x99\x84",
    			':wink:'    => "\xf0\x9f\x98\x89",
    			':cry:'     => "\xf0\x9f\x98\xa5",
    			':eek:'     => "\xf0\x9f\x98\xae",
    			':lol:'     => "\xf0\x9f\x98\x86",
    			':mad:'     => "\xf0\x9f\x98\xa1",
    			':sad:'     => "\xf0\x9f\x99\x81",
    			'8-)'       => "\xf0\x9f\x98\x8e",
    			'8-O'       => "\xf0\x9f\x98\xaf",
    			':-('       => "\xf0\x9f\x99\x81",
    			':-)'       => "\xf0\x9f\x99\x82",
    			':-?'       => "\xf0\x9f\x98\x95",
    			':-D'       => "\xf0\x9f\x98\x80",
    			':-P'       => "\xf0\x9f\x98\x9b",
    			':-o'       => "\xf0\x9f\x98\xae",
    			':-x'       => "\xf0\x9f\x98\xa1",
    			':-|'       => "\xf0\x9f\x98\x90",
    			';-)'       => "\xf0\x9f\x98\x89",
    			// This one transformation breaks regular text with frequency.
    			//     '8)' => "\xf0\x9f\x98\x8e",
    			'8O'        => "\xf0\x9f\x98\xaf",
    			':('        => "\xf0\x9f\x99\x81",
    			':)'        => "\xf0\x9f\x99\x82",
    			':?'        => "\xf0\x9f\x98\x95",
    			':D'        => "\xf0\x9f\x98\x80",
    			':P'        => "\xf0\x9f\x98\x9b",
    			':o'        => "\xf0\x9f\x98\xae",
    			':x'        => "\xf0\x9f\x98\xa1",
    			':|'        => "\xf0\x9f\x98\x90",
    			';)'        => "\xf0\x9f\x98\x89",
    			':!:'       => "\xe2\x9d\x97",
    			':?:'       => "\xe2\x9d\x93",
    		);
    	}

    	/**
    	 * Filters all the smilies.
    	 *
    	 * This filter must be added before `smilies_init` is run, as
    	 * it is normally only run once to setup the smilies regex.
    	 *
    	 * @since 4.7.0
    	 *
    	 * @param string[] $wpsmiliestrans List of the smilies' hexadecimal representations, keyed by their smily code.
    	 */
    	$wpsmiliestrans = apply_filters( 'smilies', $wpsmiliestrans );

    	if ( count( $wpsmiliestrans ) === 0 ) {
    		return;
    	}

    	/*
    	 * NOTE: we sort the smilies in reverse key order. This is to make sure
    	 * we match the longest possible smilie (:???: vs :?) as the regular
    	 * expression used below is first-match
    	 */
    	krsort( $wpsmiliestrans );

    	$spaces = wp_spaces_regexp();

    	// Begin first "subpattern".
    	$wp_smiliessearch = '/(?<=' . $spaces . '|^)';

    	$subchar = '';
    	foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
    		$firstchar = substr( $smiley, 0, 1 );
    		$rest      = substr( $smiley, 1 );

    		// New subpattern?
    		if ( $firstchar !== $subchar ) {
    			if ( '' !== $subchar ) {
    				$wp_smiliessearch .= ')(?=' . $spaces . '|$)';  // End previous "subpattern".
    				$wp_smiliessearch .= '|(?<=' . $spaces . '|^)'; // Begin another "subpattern".
    			}

    			$subchar           = $firstchar;
    			$wp_smiliessearch .= preg_quote( $firstchar, '/' ) . '(?:';
    		} else {
    			$wp_smiliessearch .= '|';
    		}

    		$wp_smiliessearch .= preg_quote( $rest, '/' );
    	}

    	$wp_smiliessearch .= ')(?=' . $spaces . '|$)/m';
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/functions.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/functions.php#L4839)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/functions.php#L4839-L4947)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#hooks)󠁿

 [apply_filters( ‘smilies’, string[] $wpsmiliestrans )](https://developer.wordpress.org/reference/hooks/smilies/)

Filters all the smilies.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_spaces_regexp()](https://developer.wordpress.org/reference/functions/wp_spaces_regexp/)`wp-includes/formatting.php` |

Returns the regexp for common whitespace characters.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

[Show 1 more](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/smilies_init/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.2.0](https://developer.wordpress.org/reference/since/2.2.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fsmilies_init%2F)
before being able to contribute a note or feedback.