Home » WordPress

去除WordPress header 的 link 标签 rel 属性

3 03月 2010 Views: No Comment Tags:

WordPress 在 2.8 版本之后,增加了几个新的 link 标签 rel 属性,例如:

<link rel="index" title="Sino Blog" href="http://www.sinoblog.org" />
<link rel="start" title="Hello World" href="http://www.sinoblog.org/2007/09/hello-world.html" />
<link rel="prev" title="QQ邮箱支持域名邮箱个性化邮件服务" href="http://www.sinoblog.org/2009/09/qq-domainmail.html" />

如果要去掉 WordPress 博客 header 部分的这些 rel 属性,可以通过修改主题支持函数(functions.php)来实现,规则是:

remove_action( $tag, $function_to_add, $priority, $accepted_args );

例如,要去掉下面的这些 link 标签:

<link rel="alternate" type="application/rss+xml" title="WP Engineer RSS Feed" href="http://www.aliyoga.com/yujia/feed/" />
<link rel="alternate" type="application/atom+xml" title="WP Engineer Atom Feed" href="http://www.aliyoga.com/yujia/feed/atom/" />
<link rel="pingback" href="http://www.aliyoga.com/yujia/xmlrpc.php" />
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://www.aliyoga.com/xmlrpc.php?rsd" />
<link rel="index" title="WP Engineer" href="http://www.aliyoga.com" />
<link rel="start" title="Use WordPress 2.7 Offline" href="http://www.aliyoga.com/shop/" />
<link rel="prev" title="Recents Drafts All Authors" href="http://www.aliyoga.com/bbs/" />

分别对应的 remove_action 代码是:

remove_action( 'wp_head', 'feed_links_extra', 3 ); // Display the links to the extra feeds such as category feeds
remove_action( 'wp_head', 'feed_links', 2 ); // Display the links to the general feeds: Post and Comment Feed
remove_action( 'wp_head', 'rsd_link' ); // Display the link to the Really Simple Discovery service endpoint, EditURI link
remove_action( 'wp_head', 'wlwmanifest_link' ); // Display the link to the Windows Live Writer manifest file.
remove_action( 'wp_head', 'index_rel_link' ); // index link
remove_action( 'wp_head', 'parent_post_rel_link', 10, 0 ); // prev link
remove_action( 'wp_head', 'start_post_rel_link', 10, 0 ); // start link
remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0 ); // Display relational links for the posts adjacent to the current post.
remove_action( 'wp_head', 'wp_generator' ); // Display the XHTML generator that is generated on the wp_head hook, WP version

在一个老外的博客看到的,记录一下
本文来源于Sino Blog http://www.sinoblog.org , 原文地址: http://www.sinoblog.org/2009/09/cleanup-wordpress-header-link-rel.html

原创文章如转载,请注明:转载自Xixis Blog [ http://www.xixis.net/ ]
本文链接地址:http://www.xixis.net/archives/wordpress-header-to-remove-the-link-tag-rel-attribute.html

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.