WordPress为指定分类的所有链接添加nofollow属性

如果出于特殊需求,你要为某个WordPress分类下的文章的所有链接都添加nofollow属性,那你可以将下面的代码添加到主题的 functions.php 文件即可:

1
2
3
4
5
6
7
8
function nofollow_cat_posts($text) {
global $post;
        if( in_category(1) ) { // 修改这里的分类ID
                $text = stripslashes(wp_rel_nofollow($text));
        }
        return $text;
}
add_filter('the_content', 'nofollow_cat_posts');

function nofollow_cat_posts($text) {
global $post;
if( in_category(1) ) { // 修改这里的分类ID
$text = stripslashes(wp_rel_nofollow($text));
}
return $text;
}
add_filter(‘the_content’, ‘nofollow_cat_posts’);

参考资料:http://www.wprecipes.com/how-to-add-nofollow-attributes-to-all-links-in-a-specific-category

本人擅长Ai、Fw、Fl、Br、Ae、Pr、Id、Ps等软件的安装与卸载,精通CSS、JavaScript、PHP、ASP、C、C++、C#、Java、Ruby、Perl、Lisp、Python、Objective-C、ActionScript、Pascal等单词的拼写,熟悉Windows、Linux、OS X、Android、iOS、WP8等系统的开关机。

通过下面的方式来联系我们:

电邮:138762189@qq.com

联系QQ:点击这里给我发消息

官方站:www.tadke.com

※ ※ 联系请加我的企鹅号 ※※

※ ※技术支持请微信联系站长 ※※

Copyright © 2023 Tadke.com. 琼ICP备20000547号