禁用 Emoji 表情

打开当前wordpress主题下的functions.php文件,加入以下代码即可:

/**
 * 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.
 *
 * @param array $plugins
 * @return array Difference betwen the two arrays
*/
function disable_emojis_tinymce( $plugins ) {
    return array_diff( $plugins, array( 'wpemoji' ) );

屏蔽头部加载 s.w.org

WordPress 默认使用 s.w.org 下的图片来渲染 emoji 表情,所以在 WordPress 头部也有 s.w.org 的DNS 解析:

<link rel='dns-prefetch' href='//s.w.org'>

但是 s.w.org 国内根本无法访问,所以这里 DNS 预解析,反而可能会影响速度,并且我们已经禁用 Emoji 功能,最好也在头部禁止 s.w.org 的DNS 解析,在 functions.php 中加载下面这行代码即可:

add_filter( 'emoji_svg_url', '__return_false' );