设计笔记

  • 1、移除WordPress版本
  • 2、移除离线编辑器开放接口
  • 3、移除前后文、第一篇文章、主页meta信息
  • 4、移除feed
  • 首页
  • 作品
  • 代码
  • 随笔
  • 关于博主
    • 豆瓣书影
  • 友情链接
  • 文章归档
  • 榜上有名
  • RSS Feed
  • GitHub
  • Twitter
  • Link

喜欢这款主题

抢先体验

移除wordpress头部无用信息

  • Tokin
  • 2013-01-28
  • 0

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

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

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

<?php
//remove_action( 'wp_head', 'wp_enqueue_scripts', 1 );
remove_action( 'wp_head', 'feed_links', 2 );
remove_action( 'wp_head', 'feed_links_extra', 3 );
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action('wp_head', 'parent_post_rel_link', 10, 0 );
remove_action('wp_head', 'start_post_rel_link', 10, 0 );
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );
//remove_action( 'wp_head', 'locale_stylesheet' );
remove_action( 'publish_future_post', 'check_and_publish_future_post',10, 1 );
//remove_action( 'wp_head', 'noindex', 1 );
//remove_action( 'wp_head', 'wp_print_styles', 8 );
//remove_action( 'wp_head', 'wp_print_head_scripts', 9 );
remove_action( 'wp_head', 'wp_generator' );
//remove_action( 'wp_head', 'rel_canonical' );
remove_action( 'wp_footer', 'wp_print_footer_scripts' );
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
remove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
add_action('widgets_init', 'my_remove_recent_comments_style');
function my_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'] ,'recent_comments_style'));
}
?>

下面说说具体使用和作用

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,不过看了一下,只有在本地那个代码才会出现,所以就没必要了,如果你有什么要补充的,欢迎留言。

文章整编自:主题吧

© 2025 设计笔记
Theme by Wing
  • {{ item.name }}
  • {{ item.name }}