缩略图

WordPress给文章外链地址添加nofollow

2026年09月27日 网站文章 会被自动插入 会被自动插入
本文最后更新于2026-09-27已经过去了7天请注意内容时效性
热度3 点赞 收藏0 评论0

什么是nofollow?

nofollow是HTML页面中a标签的属性值。它的用处是告诉搜索引擎\”不要追踪此网页上的链接\”或\”不要追踪此特定链接\”,也就是不会导出权重到此链接。

对于wordoress seo优化有着一定重要性。所以在文章内如果有外链地址,链接地址添加nofollw是很有必要的,

添加案例

添加rel=\”nofollow\”不导出自身网站权重

<a href=\"https://www.cnhacker90.com/\" rel=\"nofollow\" >90资源网</a>

使用方法

将以下代码添加到主题functions.php文件

//给文章外链添加nofollow
add_filter(\'the_content\',\'web589_the_content_nofollow\',999);
function web589_the_content_nofollow($content){
    preg_match_all(\'/href=\"(.*?)\" rel=\"external nofollow\" /\',$content,$matches);
    if($matches){
        foreach($matches[1] as $val){
            if( strpos($val,home_url())===false ) $content=str_replace(\"href=\\\"$val\\\"\", \"href=\\\"$val\\\" rel=\\\"nofollow\\\" \",$content);
        }
    }
    return $content;
}

更多技术教程,请关注90资源网www.cnhacker90.com

淚
奈
硫
正文结束 阅读本文相关话题
相关阅读
评论框
正在回复
评论列表

暂时还没有任何评论,快去发表第一条评论吧~

空白列表