我们在加载代码

<?php wp_head(); ?>

这个时候,我们会发现WordPress头部加载s.w.org

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

这个预载表情,我觉得大部分应该是用不到的,所以还是移除比较好,还能提升一些速度。

functions.php中加入以下代码即可:

/*
禁止WordPress头部加载s.w.org
https://www.wpxzt.com
*/
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 );

参与评论