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();
}
}
注意:兩個代碼只能使用其中一個,不能同時使用兩個代碼哦!