在使用百度页面优化建议的时候发现博客比平时多加载了一段从未见过的js文件,搜索得知是因为WordPress版本升级到4.2导致,因为WordPress4.2新增了对Emoji表情的支持,而使用这个表情后会从墙外加载资源,可能影响您的博客加载速度。


方法一:将如下代码添加到您主题目录的functions.php文件中
1 2 3 4 |
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' ); |
方法二:只是代码不同,依然添加到主题目录的functions.php文件中
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
/**
* 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_action( 'init', 'disable_emojis' );
/**
* Filter function used to remove the tinymce emoji plugin.
*/
function disable_emojis_tinymce( $plugins ) {
if ( is_array( $plugins ) ) {
return array_diff( $plugins, array( 'wpemoji' ) );
} else {
return array();
}
}
|
方法三:使用Disable Emojis插件来解决
如果您对代码不太熟悉,或者怕添加出错,没关系,直接安装Disable Emojis插件也可以解决此问题,点此下载:Disable Emojis插件
最后可以通过查看网站源码(Ctrl+U)搜索关键词”wp-emoji-release.min.js”,若没有搜索到结果,则代码已经禁用Emoji表情成功。
