WordPress禁止Emojis表情符号字符的功能

麦子
麦子
管理员
1234
文章
0
粉丝
优化推广330字数 467阅读1分33秒阅读模式

从WordPress5.0版本开始,程序默认自带Emojis表情符号图标的功能,我们在评论或者发布文章的是否都有这些可以发布图标的,但是有些时候不是太好看,有些人希望禁止掉这个功能。

我们直接可以用代码来禁止。我们将代码添加到当前主题 Functions.php 文件中禁止Emojis。

//禁止Emojis http://www.zhujipingjia.com/wpdisable-emojis.html
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 the emoji's http://www.zhujipingjia.com/wpdisable-emojis.html
 */
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;
}

或者我们可以使用 LeSEO插件的一键开启功能。

WordPress禁止Emojis表情符号字符的功能

投上你的一票
 
  • 本文由 麦子 发表于2024年9月26日 08:39:03
  • 转载请务必保留本文链接:https://www.zhujipingjia.com/wpdisable-emojis.html
优化推广

解决WordPress标题中的"-"被转义成"–"问题

如果我们使用默认的WordPress程序和主题且没有进行转义字符处理会在标题中如果有"-"横线的被自动转义成"–"字符的,虽然在体验上没有什么问题,但是感觉看着不是那么舒服一些。但是建议我们在优化主题...