wp_encode_emoji() WordPress Function

The wp_encode_emoji() function is used to convert Unicode characters to their corresponding HTML entities. This is necessary for displaying Emoji characters on websites that do not support Unicode characters.

wp_encode_emoji( string $content ) #

Converts emoji characters to their equivalent HTML entity.


Description

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


Top ↑

Parameters

$content

(string)(Required)The content to encode.


Top ↑

Return

(string) The encoded content.


Top ↑

Source

File: wp-includes/formatting.php

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

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

	return $content;
}


Top ↑

Changelog

Changelog
VersionDescription
4.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More