A-A+

为特定分类目录下的文章链接添加nofollow属性

2014年04月15日 编程技术 暂无评论

有些时候我们需要在某个特定的分类目录下的文章链接添加nofollow的属性,比如放置软件下载文章的分类目录,这样做可以防止搜索引擎降权。对于这样的情况,可以用几行简单的代码来解决:

[code lang="php"]
function
nofollow_cat_posts($text)
{
global
$post;
if(
in_category(1)
)
{
// SET CATEGORY ID HERE
$text
=
stripslashes(wp_rel_nofollow($text));
}
return
$text;
}
add_filter('the_content',
'nofollow_cat_posts');
[/code]

in_category(1)中的数字为分类目录ID,在WP后台的文章→分类目录,点击任意一个分类目录,地址中会有一段类似于taxonomy=category&tag_ID=6&post_type=post,其中的ID=6就是所要找的分类目录ID。

标签:

给我留言