Typecho文章内链接新窗口打开并添加nofollow的教程

默认情况Typecho文章中如果有添加链接,那么是从当前窗口跳转的,并且外链没有添加nofollow标签,不利于SEO,Typecho文章内链接新窗口并添加nofollow标签如下。

找到/var/CommonMark/HtmlRenderer.php这个文件,在105行,也就是$attrs[‘href’] = $this->escape($inline->getAttribute(‘destination’), true);代码之后添加如下两行代码:

$attrs['target'] = $this->escape(_blank, true);
$attrs['rel'] = $this->escape(nofollow, true);

最后保存查看效果,修改后的完整代码,请注意对比:

case CommonMark_Element_InlineElement::TYPE_LINK:
                $attrs['href'] = $this->escape($inline->getAttribute('destination'), true);
                $attrs['target'] = $this->escape(_blank, true);
                $attrs['rel'] = $this->escape(nofollow, true);
                if ($title = $inline->getAttribute('title')) {
                    $attrs['title'] = $this->escape($title, true);
                }

注意:Typecho 1.1及以上的版本不支持此方法。

鹿泽
鹿泽

深耕 SEO优化 十二年,从个人博客爱好者到专业谷歌优化顾问的成长之路。技术派SEO、全域流量技术运营专家,拥有多年从业经验,热衷于分析算法逻辑与推理的精准匹配。

文章: 9633