移除wordpress头部其他信息

写主题的,是不是经常见到wordpress的头部多了很多没有用的信息呢?比如wordpress版权、wordpress RSS、外部博客接口、短链接网址、wordpress自带脚本等。

对于一个折腾主题的爱好者,这些东西可是不允许存在的,我上网搜了一下,其实这一切都是wordpress的wp_head() 在作怪了。下面与大家分享怎么移除这些内容。

大家根据需要移除不需要的函数就可以了。

  1. <?php
  2. //remove_action( 'wp_head', 'wp_enqueue_scripts', 1 );
  3. remove_action( 'wp_head', 'feed_links', 2 );
  4. remove_action( 'wp_head', 'feed_links_extra', 3 );
  5. remove_action( 'wp_head', 'rsd_link' );
  6. remove_action( 'wp_head', 'wlwmanifest_link' );
  7. remove_action( 'wp_head', 'index_rel_link' );
  8. remove_action('wp_head', 'parent_post_rel_link', 10, 0 );
  9. remove_action('wp_head', 'start_post_rel_link', 10, 0 );
  10. remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
  11. //remove_action( 'wp_head', 'locale_stylesheet' );
  12. remove_action( 'publish_future_post', 'check_and_publish_future_post', 10, 1 );
  13. //remove_action( 'wp_head', 'noindex', 1 );
  14. //remove_action( 'wp_head', 'wp_print_styles', 8 );
  15. //remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
  16. remove_action( 'wp_head', 'wp_generator' );
  17. //remove_action( 'wp_head', 'rel_canonical' );
  18. remove_action( 'wp_footer', 'wp_print_footer_scripts' );
  19. remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
  20. remove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
  21. add_action('widgets_init', 'my_remove_recent_comments_style');
  22. function my_remove_recent_comments_style() {
  23. global $wp_widget_factory;
  24. remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'] , 'recent_comments_style'));
  25. }
  26. ?>

下面说说具体使用和作用

1、移除WordPress版本

在head区域,可以看到如下代码:

<meta name="generator" content="WordPress 3.1.2" />

这是隐性显示的WordPress版本信息,默认添加。可以被黑客利用,攻击特定版本的WordPress漏洞。清除代码:

remove_action( 'wp_head', 'wp_generator' );

2、移除离线编辑器开放接口

remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );

3、移除前后文、第一篇文章、主页meta信息

remove_action( 'wp_head', 'index_rel_link' ); // Removes the index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // Removes the prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // Removes the start link
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); // Removes the relational links for the posts adjacent to the current post.

4、移除feed

remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );

到这里你的头部也就干净了。话说还可以移除一个3.0以后添加的js,不过看了一下,只有在本地那个代码才会出现,所以就没必要了,如果你有什么要补充的,可以留言讨论。

参考:优化wp_head()精简WordPress头部 我也不知道这个是不是源头,若不对的,可以给我留言。

声明: 未经本站许可,谢绝转载!

2 个主题帖 其中:热心观众:0 个, 管理员:0 个

  1. wpbars
    0楼
    wpbars:

    没有多少人气哦。加油。

    2011-10-07 07:50
  2. wpbars
    0楼
    wpbars:

    这是是重新编辑,我们使用的是ajax评论哦,还可以重新编辑的。

    2011-10-07 07:51

抱歉,评论被关闭