现在的位置: 首页技术Learn>正文
让WordPress评论者以及评论内容中的链接在新窗口打开的方法
2011年01月08日 技术Learn 暂无评论 ⁄ 被围观 214 次+

步骤一

找到 /wp-includes/formatting.php

搜索 function _make_url_clickable_cb

会看到以下代码

function _make_url_clickable_cb($matches) {

$ret = '';

$url = $matches[2];

$url = clean_url($url);

if ( empty($url) )

return $matches[0];

// removed trailing [.,;:] from URL

if ( in_array(substr($url, -1), array('.', ',', ';', ':')) === true ) {

$ret = substr($url, -1);

$url = substr($url, 0, strlen($url)-1);

}

return $matches[1] . "<a href="$url" rel="nofollow">$url</a>" . $ret;

}

那么问题就解决了,只要把

<a href=\"$url\" rel=\"nofollow\">$url</a>

改为

<a href=\"$url\" rel=\"nofollow\" target=\"_blank\">$url</a>

就可以使评论中的链接在新窗口打开了。

步骤二

/wp-includes/comment-template.php文件中修改。

找到下面这段:

$return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";

改成

$return = "<a href='$url' rel='external nofollow' class='url' target='_blank'>$author</a>";

然后保存上传即可。





给我留言

留言无头像?

无觅相关文章插件,快速提升流量

×
订阅本站
腾讯微博