去掉wordpress顶部的s.w.org及下面预载表情的JS

作者: admin 分类: 运营、维护日志 发布时间: 2017-08-04 21:46

今天打开网站源码查看了一下,发现源码顶部有一个网址链接是:s.w.org,然后这行下面还有一些JS代码。

搜索查询了一下答案,上面的这个网址与DNS有关系,下面的JS代码是预加载表情的,比如评论时插入头像之类的,没什么用处,可以屏蔽。

百度了两篇文章,终于去掉了顶部的s.w.org及下面预载表情的JS

方法是在WP程序主题中的functions.php文件中,加入下面的代码:

// 百度到的,禁止加载网页源码中的s.w.org网址,以及下面的一段JS,这段原来是与评论加载图片有关系的

function remove_dns_prefetch( $hints, $relation_type ) {
if ( ‘dns-prefetch’ === $relation_type ) {
return array_diff( wp_dependencies_unique_hosts(), $hints );
}
return $hints;
}
add_filter( ‘wp_resource_hints’, ‘remove_dns_prefetch’, 10, 2 );

 

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();
}
}

// 禁止加载标记结束

相关文章

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

Powered by 草根站长笔记 © 2015-2020 草根站长笔记 Inc.版权所有,禁止转载