图片待添加
图片待添加

WordPress访问加速:禁用移除 wpemoji 表情代码

2020-02-24 15:20 分类:WordPress主题开发制作教程 阅读(次阅读) 标签:,

WordPress 自从 4.2 版本之后,会在网站前端生成的页面源码中自动加载一段用于支持 emjo 表情的脚本,包括对应的 JS 和 CSS 样式代码,代码内容如下:

<script type="text/javascript">
window._wpemojiSettings = {"baseUrl":"http:\/\/s.w.org\/images\/core\/emoji\/72x72\/","ext":".png","source":{"concatemoji":"http:\/\/localhost\/wordpress\/wp-includes\/js\/wp-emoji-release.min.js?ver=4.3"}};
!function(a,b,c){function d(a){var c=b.createElement("canvas"),d=c.getContext&&c.getContext("2d");return d&&d.fillText?(d.textBaseline="top",d.font="600 32px Arial","flag"===a?(d.fillText(String.fromCharCode(55356,56812,55356,56807),0,0),c.toDataURL().length>3e3):(d.fillText(String.fromCharCode(55357,56835),0,0),0!==d.getImageData(16,16,1,1).data[0])):!1}function e(a){var c=b.createElement("script");c.src=a,c.type="text/javascript",b.getElementsByTagName("head")[0].appendChild(c)}var f,g;c.supports={simple:d("simple"),flag:d("flag")},c.DOMReady=!1,c.readyCallback=function(){c.DOMReady=!0},c.supports.simple&&c.supports.flag||(g=function(){c.readyCallback()},b.addEventListener?(b.addEventListener("DOMContentLoaded",g,!1),a.addEventListener("load",g,!1)):(a.attachEvent("onload",g),b.attachEvent("onreadystatechange",function(){"complete"===b.readyState&&c.readyCallback()})),f=c.source||{},f.concatemoji?e(f.concatemoji):f.wpemoji&&f.twemoji&&(e(f.twemoji),e(f.wpemoji)))}(window,document,window._wpemojiSettings);
</script>
<style type="text/css">
img.wp-smiley,
img.emoji {
display: inline !important;
border: none !important;
box-shadow: none !important;
height: 1em !important;
width: 1em !important;
margin: 0 .07em !important;
vertical-align: -0.1em !important;
background: none !important;
padding: 0 !important;
}
</style>

WordPress主题访问加速:禁用移除 wpemoji 表情代码

这个wpemoji表情功能我们基本上都是用不着的,尤其WordPress企业主题一般都不会在文章中涉及到表情符号,所以去掉来净化代码是完全必要的,具体方法也是非常简单,只需要找到当前网站使用的主题文件夹中的 functions.php 文件(在wp-content/themes/下面的你的主题目录),在里面填写如下2行代码即可禁用移除 wpemoji 代码:

// RemoveEmojiIcons
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');

你也可以在functions.php 文件(在wp-content/themes/下面的你的主题目录)加入下面这段代码禁用移除 wpemoji 代码:

/**去除window._wpemojiSettings**/
remove_action( 'admin_print_scripts', 'print_emoji_detection_script');
remove_action( 'admin_print_styles', 'print_emoji_styles');
remove_action( 'wp_head', 'print_emoji_detection_script', 7);
remove_action( 'wp_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');

 


本文地址: https://www.wpyi.com/delete-head-wpemoji.html