A-A+

禁止WordPress头部加载s.w.org

2017年06月14日 编程技术 暂无评论

文章接上一篇,在清理了 emoji 表情之后,整个 wordpress 显得干净多了,至少是从源代码来看,虽然 js+css 都已经去掉了,但加载其国外网站的链接地址还在,如下:

当然不用说,emoji 表情都不用了,还要这个加载地址干什么,直接动手切除掉。

将下面的代码添加到主题functions.php模板中:

方法一:

remove_action( 'wp_head', 'wp_resource_hints', 2 );

方法二:

  1. function remove_dns_prefetch( $hints$relation_type ) {  
  2. if ( 'dns-prefetch' === $relation_type ) {  
  3. return array_diff( wp_dependencies_unique_hosts(), $hints );  
  4. }  
  5. return $hints;  
  6. }  
  7. add_filter( 'wp_resource_hints', 'remove_dns_prefetch', 10, 2 );  

方法二貌似兼容性更好些。

附带一个禁止加载表情代码:

  1. // Remove emoji script  
  2. remove_action( 'wp_head', 'print_emoji_detection_script', 7 );  
  3. remove_action( 'wp_print_styles', 'print_emoji_styles' );  
  4. add_filter( 'emoji_svg_url', '__return_false' );  
标签:

给我留言

Copyright © 小虎博客 保留所有权利.   Theme  Ality

用户登录