欢迎您光临自学哈网,只为分享网络知识教程,供大家学习参考!

「自学哈网」如何禁用WordPress表情符号Emojis

作者 : 自学哈 本文共2362个字,预计阅读时间需要6分钟 2022-09-11 共204人阅读
也想出现在这里? 联系我们

我们可以进行许多网络性能优化和调整,以使WordPress网站加载速度更快。其中一种简单的优化方法是禁止加载表情符号Emojis。表情符号(Emojis)是用于表达想法或情感的小图标。尽管这些图标很有趣,但它们对于WordPress网站真的必要吗?对于很多网站来说,或者这些只是增加了不必要的额外加载时间。

当WordPress 4.2发布时,针对较旧版本的浏览器WordPress核心中添加了对表情符号的支持。最大的问题是,它会在WordPress网站上生成一个额外的HTTP请求,以加载wp-emoji-release.min.js文件。每个页面都会载入此文件,尽管此文件只有10.5 KB,但随着时间的推移,类似的东西会累加起来。

wp-emoji-release

Emojis表情符号JS文件

有两种不同的方法禁用WordPress表情符号Emojis:使用免费插件或代码来实现。

使用插件禁用Emojis
修改代码禁用Emojis

1. 使用插件禁用Emojis

禁用表情符号Emojis的第一种方法是简单地使用由Ryan Hellyer开发的名为Disable Emojis的免费插件。

disable-emojis-wordpress-plugin

Disable Emojis插件

这是一个超轻量级的插件,确切地说只有9 KB。该插件目前拥有70,000多个激活安装,100%的好评5星。注意:Emoticons和emojis仍然可以在内置支持它们的浏览器中使用。该插件仅删除了多余的JavaScript文件,该文件用于在较旧的浏览器中添加对表情符号的支持。

还有一个名为Emoji settings的免费替代插件。这是在考虑到多站点的情况下开发的,  并为用户提供了禁用表情符号本身的选项。

emoji-settings

Emoji settings插件

启用插件后,用户可以在WordPress仪表板的“设置-撰写”中选中或取消选中“Enable emoji support”。

您还可以使用perfmatters类的高级插件,该插件支持禁用emoji表情以及WordPress网站的其他优化功能。

disable-emojis-with-perfmatters

使用插件perfmatters禁用emojis

2. 修改代码禁用Emojis

如果您不想安装各种杂七杂八的插件,也可以使用代码禁用表情符号。只需将以下内容添加到WordPress主题的functions.php文件中。这实质是Disable Emoji插件的代码。

警告:修改代码前请先备份源文件,以免因操作不当导致网站出现问题,可以通过备份恢复!

/**

* 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;

}

本站声明:
本站所有资源来源于网络,分享目的仅供大家学习和交流!如若本站内容侵犯了原著者的合法权益,可联系邮箱976157886@qq.com进行删除。
自学哈专注于免费提供最新的分享知识、网络教程、网络技术的资源分享平台,好资源不私藏,大家一起分享!

自学哈网 » 「自学哈网」如何禁用WordPress表情符号Emojis
也想出现在这里? 联系我们
© 2022 Theme by - 自学哈网 & WordPress Theme. All rights reserved 浙ICP备2022016594号