Typecho默认的a
标签是只有href
属性的,也就是覆盖本页打开。
但是大多数情况下我们都希望链接从新窗口或新标签页打开。
默认html
下面是默认的html代码。
<a href="https://www.ipaddr.host">
千思网
</a>
希望的html
页内链接不仅要从新窗口打开,而且从seo
方面考虑,我们还希望为站外的url添加nofollow属性。
那么要达到上述的效果,html代码应该是下面这样的,增加了target="_blank" rel="nofollow"
。
<a href="https://www.ipaddr.host" target="_blank" rel="nofollow">
千思网
</a>
变更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
。
<p>
<a href="https://www.ipaddr.host" target="_blank">千思网</a><br>
<a href="http://www.baidu.com" target="_blank" rel="nofollow">百度</a>
</p>
现在的版本 HtmlRenderer.php 文件在哪? 好像没有了怎么办
没有升级新版,抱歉啦,你可以搜索一下。
还是不太习惯 WP后遗症
哈哈,习惯了就感觉很好用,我也是 wp 转过来的。貌似后台可以改为html的吧。
请问是否不用markdown后就失效了?
Markdown 不是很好嘛!
这个倒是没有测试过,你测测看看。
确实是跟markdown有关 看来又得选编辑器了