wp_encode_emoji()
Convert emoji characters to their equivalent HTML entity.
This allows us to store emoji in a DB using the utf8 character set.
Used By: wp_staticize_emoji()
1 time — 0.00028 sec (fast) | 50000 times — 8.13 sec (fast)
No Hooks.
Return
String
. The encoded content.
Usage
wp_encode_emoji( $content );
- $content(string) (required)
- The content to encode.
Examples
#1 Demonstration of replacement of smiley characters to HTML entities in a string
$str = '😃 😁 😝 ❄ 😇'; $str = wp_encode_emoji( $str ); // $str is now equal to: 🌛 🌌 🍦 ❄ 🍪
Changelog
Since 4.2.0 | Introduced. |
wp_encode_emoji() wp encode emoji code WP 6.7.1
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; }