wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_encode_emoji › WordPress Function

Since4.2.0
Deprecatedn/a
wp_encode_emoji ( $content )
Parameters:
  • (string) $content The content to encode.
    Required: Yes
Returns:
  • (string) The encoded content.
Defined at:
Codex:

Converts emoji characters to their equivalent HTML entity.

This allows us to store emoji in a DB using the utf8 character set.


Source

function wp_encode_emoji( $content ) {
	$emoji = _wp_emoji_list( 'partials' );

	foreach ( $emoji as $emojum ) {
		$emoji_char = html_entity_decode( $emojum );
		if ( str_contains( $content, $emoji_char ) ) {
			$content = preg_replace( "/$emoji_char/", $emojum, $content );
		}
	}

	return $content;
}