文章作者:姜南(Slyar) 文章来源:Slyar Home (www.slyar.com) 转载请注明,谢谢合作。
2009.6.27 更新至WordPress 2.8版本支持
呵呵,看到Wordpress中文论坛有人问这个问题,正好拿来做话题写~~
问题就是如何让WP评论中的链接默认使用新窗口打开。
找到 wp-includes\formatting.php
搜索 function _make_url_clickable_cb
会看到以下代码
1 2 3 4 5 6 7 8 9 10 11 12 13 |
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; } |
那么问题就解决了,只要把
1 |
<a href=\"$url\" rel=\"nofollow\">$url</a> |
改为
1 |
<a href=\"$url\" rel=\"nofollow\" target=\"_blank\">$url</a> |
就可以使评论中的链接在新窗口打开了。
转载请注明:Slyar Home » 让WordPress评论中链接在新窗口打开