您要在您的 WordPress 网站上禁用表情符号吗?
表情符号是用于表达感受或情绪的小图标。 WordPress 加载额外的 CSS 和 JavaScript 文件以添加表情符号支持,一些用户可能希望删除它以提高性能和速度。
在本文中,我们将向您展示如何在 WordPress 中轻松禁用表情符号。
什么是表情符号?
表情符号是互联网上使用的小图标或笑脸。
表情符号起源于日本,已进入 Unicode 字符集,现在受到台式电脑以及 iOS 和 Android 移动设备的支持。
表情符号功能在 WordPress 4.2 中首次引入,添加此功能的主要原因是添加对中文、日文和韩文字符集的本地支持。
默认情况下,WordPress 会加载一个额外的 JavaScript 文件和一些 CSS 来添加表情符号支持。
您可以通过查看您网站的源代码或使用检查工具来查看它。
然而,一些网站所有者可能希望通过不下载额外的代码和脚本来禁用这种额外的表情符号支持来提高 WordPress 的速度和性能。
注意:当我们说在 WordPress 中禁用表情符号时,我们的意思是禁用 WordPress 用于处理表情符号的额外检查和脚本。 您仍然可以在您的网站上使用表情符号,支持它们的浏览器仍然可以显示它们。
话虽如此,让我们来看看如何轻松禁用 WordPress 中的表情符号支持。
自定义代码方法
通过自定义代码方法,无需修改你的主题,将一下代码加入进去即可。
/** * Disable the emoji's */ function disable_emojis() { remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); remove_action( 'wp_print_styles', 'print_emoji_styles' ); remove_action( 'admin_print_styles', 'print_emoji_styles' ); remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); add_filter( 'tiny_mce_plugins', 'disable_emojis_tinymce' ); add_filter( 'wp_resource_hints', 'disable_emojis_remove_dns_prefetch', 10, 2 ); } add_action( 'init', 'disable_emojis' ); /** * Filter function used to remove the tinymce emoji plugin. * * @param array $plugins * @return array Difference betwen the two arrays */ function disable_emojis_tinymce( $plugins ) { if ( is_array( $plugins ) ) { return array_diff( $plugins, array( 'wpemoji' ) ); } else { return array(); } } /** * Remove emoji CDN hostname from DNS prefetching hints. * * @param array $urls URLs to print for resource hints. * @param string $relation_type The relation type the URLs are printed for. * @return array Difference betwen the two arrays. */ function disable_emojis_remove_dns_prefetch( $urls, $relation_type ) { if ( 'dns-prefetch' == $relation_type ) { /** This filter is documented in wp-includes/formatting.php */ $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/2/svg/' ); $urls = array_diff( $urls, array( $emoji_svg_url ) ); } return $urls; }