首页 » 网站技术 » 网站框架 » 正文

去掉wordpress没用的头部和版权等信息,优化generator标签

wordpress优化generator标签 去掉没用的头部和版权等信息方法介绍:

使用了wp_head()函数产生了很多多余的东西,那么应该如何去除了?打开functions.php文件。
wordpress 的每个主题(模板)目录下都 应该配 有一个functions.php文件
那么我们就对 每个wordpress 主题的functions.php文件 阻止一些head头部不必要状态!

wordpress在默认情况下,头部会出现很多平时用不到的html代码,比如:

复制代码代码如下:
<link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0 – all posts” href=”http://blog.jb51.net/feed” />
<link rel=”alternate” type=”application/rss+xml” title=”RSS 2.0 – all comments” href=”http://blog.jb51.net/comments/feed” />
<link rel=”pingback” href=”http://blog.jb51.net/xmlrpc.php” />
<link rel=”EditURI” type=”application/rsd+xml” title=”RSD” href=”http://blog.jb51.net/xmlrpc.php?rsd” />
<link rel=”wlwmanifest” type=”application/wlwmanifest+xml” href=”http://blog.jb51.net/wp-includes/wlwmanifest.xml” />
<link rel=’index’ title=’SBM Stone Crusher Machine|Grinding Mill’ href=’http://blog.jb51.net’ />
<meta name=”generator” content=”WordPress 3.4″ />

上面的标签中,比如generator,将会暴露你的博客程序用的是哪个版本,这个信息泄漏有时会对博客的安全产生一定的影响。同时,也并不需要用这么些标签。
去掉一些不用的标签

一个更直接的方法就是在wodpress目录下修改wp-includes目录下的default-filters.php,大概在180多行:
复制代码代码如下:
//add_action( ‘wp_head’, ‘feed_links’, 2 );
//add_action( ‘wp_head’, ‘feed_links_extra’, 3 );
//add_action( ‘wp_head’, ‘rsd_link’ );
//add_action( ‘wp_head’, ‘wlwmanifest_link’ );
//add_action( ‘wp_head’, ‘index_rel_link’ );
//add_action( ‘wp_head’, ‘parent_post_rel_link’, 10, 0 );
//add_action( ‘wp_head’, ‘start_post_rel_link’, 10, 0 );
//add_action( ‘wp_head’, ‘adjacent_posts_rel_link_wp_head’, 10, 0 );
add_action( ‘wp_head’, ‘locale_stylesheet’ );
add_action( ‘publish_future_post’, ‘check_and_publish_future_post’, 10, 1 );
add_action( ‘wp_head’, ‘noindex’, 1 );
add_action( ‘wp_head’, ‘wp_print_styles’, 8 );
add_action( ‘wp_head’, ‘wp_print_head_scripts’, 9 );
//add_action( ‘wp_head’, ‘wp_generator’ );
//add_action( ‘wp_head’, ‘rel_canonical’ );
add_action( ‘wp_footer’, ‘wp_print_footer_scripts’ );
//add_action( ‘wp_head’, ‘wp_shortlink_wp_head’, 10, 0 );
add_action( ‘template_redirect’, ‘wp_shortlink_header’, 11, 0 );

不需要的直接//注释掉就行了。一般看下就应该明白是什么意思的。这样可以保证html头部不再有其它的代码了。去掉了wordpress的generator标签。

但是在firefox下又出现了我不喜欢的admin bar!如何去除了,还是在functions.php添加如下代码即可:
add_filter( ‘show_admin_bar’, ‘__return_false’ );



本文共 2 个回复

发表评论

*

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据