Title: convert_smilies
Published: April 25, 2014
Last modified: August 20, 2026

---

# convert_smilies( string $text ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#user-contributed-notes)

Converts text equivalent of smilies to images.

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

Will only convert smilies if the option ‘use_smilies’ is true and the global used
in the function isn’t empty.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#parameters)󠁿

 `$text`stringrequired

Content to convert smilies from text.

## 󠀁[Return](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#return)󠁿

 string Converted content with text smilies replaced with images.

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

    ```php
    function convert_smilies( $text ) {
    	global $wp_smiliessearch;

    	if ( ! get_option( 'use_smilies' ) || empty( $wp_smiliessearch ) ) {
    		// Return default text.
    		return $text;
    	}

    	// HTML loop taken from texturize function, could possible be consolidated.
    	$textarr = preg_split( '/(<[^>]*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE ); // Capture the tags as well as in between.

    	if ( false === $textarr ) {
    		// Return default text.
    		return $text;
    	}

    	// Loop stuff.
    	$stop   = count( $textarr );
    	$output = '';

    	// Ignore processing of specific tags.
    	$tags_to_ignore       = 'code|pre|style|script|textarea';
    	$ignore_block_element = '';

    	for ( $i = 0; $i < $stop; $i++ ) {
    		$content = $textarr[ $i ];

    		// If we're in an ignore block, wait until we find its closing tag.
    		if ( '' === $ignore_block_element && preg_match( '/^<(' . $tags_to_ignore . ')[^>]*>/', $content, $matches ) ) {
    			$ignore_block_element = $matches[1];
    		}

    		// If it's not a tag and not in ignore block.
    		if ( '' === $ignore_block_element && strlen( $content ) > 0 && '<' !== $content[0] ) {
    			$content = preg_replace_callback( $wp_smiliessearch, 'translate_smiley', $content );
    		}

    		// Did we exit ignore block?
    		if ( '' !== $ignore_block_element && '</' . $ignore_block_element . '>' === $content ) {
    			$ignore_block_element = '';
    		}

    		$output .= $content;
    	}

    	return $output;
    }
    ```

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

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

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

Retrieves an option value based on an option name.

  |

| Used by | Description | 
| [_wp_apply_block_content_filters()](https://developer.wordpress.org/reference/functions/_wp_apply_block_content_filters/)`wp-includes/blocks.php` |

Applies standard content filters similar to the ‘the_content’ filter.

  | 
| [get_the_block_template_html()](https://developer.wordpress.org/reference/functions/get_the_block_template_html/)`wp-includes/block-template.php` |

Returns the markup for the current template.

  |

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

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

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 3 content](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#comment-content-1495)
 2.    [Codex](https://profiles.wordpress.org/codex/)  [  11 years ago  ](https://developer.wordpress.org/reference/functions/convert_smilies/#comment-1495)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fconvert_smilies%2F%23comment-1495)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fconvert_smilies%2F%23comment-1495)
 4.  **Displays text with converted smilies**
 5.      ```php
         echo convert_smilies("This smiley is going to show as an image... :) ");
         ```
     
 6.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fconvert_smilies%2F%3Freplytocom%3D1495%23feedback-editor-1495)
 7.   [Skip to note 4 content](https://developer.wordpress.org/reference/functions/convert_smilies/?output_format=md#comment-content-1901)
 8.    Anonymous User  [  10 years ago  ](https://developer.wordpress.org/reference/functions/convert_smilies/#comment-1901)
 9.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fconvert_smilies%2F%23comment-1901)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fconvert_smilies%2F%23comment-1901)
 10. Make your plugin generated content parse emoticons:
 11.     ```php
         add_filter( "my_plugin_content_handle", "convert_smilies" );
     
         echo apply_filters( "my_plugin_content_handle", "Howdy! ;) Generated with <3 by My Custom Plugin" );
         ```
     
 12.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fconvert_smilies%2F%3Freplytocom%3D1901%23feedback-editor-1901)

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