Title: wp_staticize_emoji
Published: April 23, 2015
Last modified: May 20, 2026

---

# wp_staticize_emoji( string $text ): string

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/wp_staticize_emoji/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/wp_staticize_emoji/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/wp_staticize_emoji/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/wp_staticize_emoji/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/wp_staticize_emoji/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/wp_staticize_emoji/?output_format=md#changelog)

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

Converts emoji to a static img element.

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

 `$text`stringrequired

The content to encode.

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

 string The encoded content.

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

    ```php
    function wp_staticize_emoji( $text ) {
    	if ( ! str_contains( $text, '&#x' ) ) {
    		if ( ( function_exists( 'mb_check_encoding' ) && mb_check_encoding( $text, 'ASCII' ) ) || ! preg_match( '/[^\x00-\x7F]/', $text ) ) {
    			// The text doesn't contain anything that might be emoji, so we can return early.
    			return $text;
    		} else {
    			$encoded_text = wp_encode_emoji( $text );
    			if ( $encoded_text === $text ) {
    				return $encoded_text;
    			}

    			$text = $encoded_text;
    		}
    	}

    	$emoji = _wp_emoji_list( 'entities' );

    	// Quickly narrow down the list of emoji that might be in the text and need replacing.
    	$possible_emoji = array();
    	foreach ( $emoji as $emojum ) {
    		if ( str_contains( $text, $emojum ) ) {
    			$possible_emoji[ $emojum ] = html_entity_decode( $emojum );
    		}
    	}

    	if ( ! $possible_emoji ) {
    		return $text;
    	}

    	/** This filter is documented in wp-includes/formatting.php */
    	$cdn_url = apply_filters( 'emoji_url', 'https://s.w.org/images/core/emoji/17.0.2/72x72/' );

    	/** This filter is documented in wp-includes/formatting.php */
    	$ext = apply_filters( 'emoji_ext', '.png' );

    	$output = '';
    	/*
    	 * HTML loop taken from smiley function, which was taken from texturize function.
    	 * It'll never be consolidated.
    	 *
    	 * First, capture the tags as well as in between.
    	 */
    	$textarr = preg_split( '/(<.*>)/U', $text, -1, PREG_SPLIT_DELIM_CAPTURE );
    	$stop    = count( $textarr );

    	// 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] && str_contains( $content, '&#x' ) ) {
    			foreach ( $possible_emoji as $emojum => $emoji_char ) {
    				if ( ! str_contains( $content, $emojum ) ) {
    					continue;
    				}

    				$file = str_replace( ';&#x', '-', $emojum );
    				$file = str_replace( array( '&#x', ';' ), '', $file );

    				$entity = sprintf( '<img src="%s" alt="%s" class="wp-smiley" style="height: 1em; max-height: 1em;" />', $cdn_url . $file . $ext, $emoji_char );

    				$content = str_replace( $emojum, $entity, $content );
    			}
    		}

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

    		$output .= $content;
    	}

    	// Finally, remove any stray U+FE0F characters.
    	$output = str_replace( '&#xfe0f;', '', $output );

    	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.0/src/wp-includes/formatting.php#L6028)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/formatting.php#L6028-L6113)

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

 [apply_filters( ’emoji_ext’, string $extension )](https://developer.wordpress.org/reference/hooks/emoji_ext/)

Filters the extension of the emoji png files.

 [apply_filters( ’emoji_url’, string $url )](https://developer.wordpress.org/reference/hooks/emoji_url/)

Filters the URL where emoji png images are hosted.

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

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

Returns arrays of emoji data.

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

Converts emoji characters to their equivalent HTML entity.

  | 
| [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.

  |

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

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

Converts emoji in emails into static images.

  |

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

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

## User Contributed Notes

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