Typecho Wiki
每一个作品都值得被记录

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

Typecho维基君Typecho教程 • 1647次浏览 • 发布 2017-11-06 • 更新 2017-11-06
极致加速的V2Ray 助您畅享全球网络 & 搬瓦工VPS最新优惠码
🛜自用大流量超低月租手机卡推荐榜单 #拒绝流量焦虑

默认情况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.Wiki所有文章均包含本声明。
本文检索关键词:typecho
厂商投放

【腾讯云】🎉五一云上盛惠!云服务器99元/月续费同价!

腾讯云五一劳动节海量产品 · 轻松上云!云服务器首年1.8折起,买1年送3个月!超值优惠,性能稳定,让您的云端之旅更加畅享。快来腾讯云选购吧!

广告
添加新评论 »