The emoji_url WordPress PHP filter allows you to modify the URL where emoji PNG images are hosted.
Usage
add_filter('emoji_url', 'your_custom_function', 10, 1); function your_custom_function($url) { // your custom code here return $url; }
Parameters
$url
(string): The emoji base URL for PNG images.
More information
See WordPress Developer Resources: emoji_url
Examples
Change emoji URL to a custom CDN
Use a custom CDN to serve emoji images faster:
add_filter('emoji_url', 'custom_emoji_url', 10, 1); function custom_emoji_url($url) { $custom_cdn = 'https://my-custom-cdn.com/emoji/'; return $custom_cdn; }
Use local emoji images
Serve emoji images from your own server:
add_filter('emoji_url', 'local_emoji_url', 10, 1); function local_emoji_url($url) { $local_emoji = get_stylesheet_directory_uri() . '/images/emoji/'; return $local_emoji; }
Append version number to emoji URL
Add a version number to the emoji URL to avoid caching issues:
add_filter('emoji_url', 'versioned_emoji_url', 10, 1); function versioned_emoji_url($url) { $version = '?v=1.0'; return $url . $version; }
Serve emoji images from a subdomain
Use a subdomain to host your emoji images:
add_filter('emoji_url', 'subdomain_emoji_url', 10, 1); function subdomain_emoji_url($url) { $subdomain_url = 'https://emoji.example.com/'; return $subdomain_url; }
Serve different emoji images based on user agent
Serve different emoji images depending on the user’s browser:
add_filter('emoji_url', 'browser_based_emoji_url', 10, 1); function browser_based_emoji_url($url) { $user_agent = $_SERVER['HTTP_USER_AGENT']; if (strpos($user_agent, 'Firefox') !== false) { return 'https://firefox-emoji.example.com/'; } elseif (strpos($user_agent, 'Chrome') !== false) { return 'https://chrome-emoji.example.com/'; } else { return $url; } }