php target标签,为Typecho文章页url标签添加nofollow和target属性

Typecho默认的a标签是只有href属性的,也就是覆盖本页打开。

但是大多数情况下我们都希望链接从新窗口或新标签页打开。

默认html

下面是默认的html代码。

千思网

希望的html

页内链接不仅要从新窗口打开,而且从seo方面考虑,我们还希望为站外的url添加nofollow属性。

那么要达到上述的效果,html代码应该是下面这样的,增加了target="_blank" rel="nofollow"。

千思网

变更typecho代码

要达到上述效果,可以直接更改typecho的php代码。

修改/var/CommonMark/HtmlRenderer.php文件。

修改前

下面是修改前的代码104 case CommonMark_Element_InlineElement::TYPE_LINK:

105 $attrs['href'] = $this->escape($inline->getAttribute('destination'), true);

106 if ($title = $inline->getAttribute('title')) {

107 $attrs['title'] = $this->escape($title, true);

108 }

修改后

下面是修改后的代码,请将107行中qiansw.com替换为你的域名。104 case CommonMark_Element_InlineElement::TYPE_LINK:

105 $attrs['href'] = $this->escape($inline->getAttribute('destination'), true);

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

107 if ( !substr_count($attrs['href'],"qiansw.com") ) {

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

109 }

110 if ($title = $inline->getAttribute('title')) {

111 $attrs['title'] = $this->escape($title, true);

112 }

最终效果

指定域下面的连接不加nofollow,站外链接加nofollow。

千思网

百度

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值