WordPress 新版升级是相当的快,一晃眼已经是 WordPress4.4.1 版了。每当打开 WordPress 站点,你都会感觉到很慢,这是因为 WordPress 加载 s.w.org 网站中的 emoji 表情造成的。

今天写这个教程可以彻底去除 WordPress 加载 s.w.org,禁用 emoji 表情。

如下代码,添加到主题 functions.php 文件中即可。

/**
 * Disable emoji
 */
function disable_wp05_emoji() {
	remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
	remove_action( 'wp_print_styles', 'print_emoji_styles' );
	remove_action('embed_head', 'print_emoji_detection_script');
	remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
	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_action( 'init', 'disable_wp05_emoji' );

以上代码适合一般用途,如果你觉得文章编辑器(Tinymce)中还有 emoji 表情不爽,你可以添加如下代码,完全干掉所有 emoji 表情。

/**
 * Disable emoji
 */
function disable_wp05_emoji() {
	remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
	remove_action( 'wp_print_styles', 'print_emoji_styles' );
	remove_action('embed_head', 'print_emoji_detection_script');
	remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
	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_wp05_emoji' );
/**
 * remove the tinymce emoji plugin.
 */
function disable_emojis_tinymce( $plugins ) {
    if ( is_array( $plugins ) ) {
        return array_diff( $plugins, array( 'wpemoji' ) );
    } else {
        return array();
    }
}

注意:两个代码只能使用其中一个,不能同时使用两个代码哦!