在看文章之前请确定你已明确标题意思:是评论内容里的超链接,而非评论者的网站链接。
自上次解决了《两个遗留问题》之一的《win主机下代码配置wordpress的SMTP邮件发送》后,本问题迟迟得不到解决(不用编辑器、不用a标签),最后不了了之,索性屏蔽了评论内容里的链接的超链转换。而就在刚才,这个问题终于得到解决。
找到 wp-includes\formatting.php
搜索 function _make_url_clickable_cb
会看到以下代码:
- function _make_url_clickable_cb($matches) {
-
matches[2]; - if ( ')' ==
url, '(' ) ) { - // If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it, add the closing parenthesis to the URL.
- // Then we can let the parenthesis balancer do its thing below.
-
matches[3]; - $suffix = '';
- } else {
-
matches[3]; - }
- // Include parentheses in the URL only if paired
- while ( substr_count(
url, ')' ) ) { -
url, ')' ) . $suffix; -
url, 0, strrpos( $url, ')' ) ); - }
-
url); - if ( emptyempty($url) )
- return $matches[0];
- return
url\" rel=\"nofollow\"> suffix; - }
然后修改其中:
- return
url\" rel=\"nofollow\"> suffix;
修改为:
- return
url\" rel=\"nofollow\" target=\"_blank\"> suffix;
这样,评论内容中的超链接就能在新窗口打开了。