首页 » WordPress教程 » 正文

如何让WordPress评论中的链接在新窗口打开

WordPress中很少使用target=_blank元素,也就是在新窗口打开,这样就容易损失流量,像评论中的链接如果能在新窗口打开就会还很多。那我们怎么实现在新窗口打开评论中的链接链接呢,小菜在网上找了下,有两种方法,可以修改代码来实现,也可以用插件来实现,因为装插件会影响WordPress的速度,而且修改代码很简单,所以插件法就不说了。下面是修改代码的方法:
打开wp-includes目录下comment-template.php文件。查找”function get_comment_author_link”找到以下这样一段代码:
function get_comment_author_link( $comment_ID = 0 ) {
/** @todo Only call these functions when they are needed. Include in if... else blocks */
$url = get_comment_author_url( $comment_ID );
$author = get_comment_author( $comment_ID );
if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "<a href='$url' rel='external nofollow' class='url' >$author</a>";
return apply_filters('get_comment_author_link', $return);
}

因版本不同代码可能会有些差异,小菜用的是3.42.
将其中

<a href=’$url’ rel=’external nofollow’>$author</a>

添加target_blank更改成

<a href=’$url’ rel=’external nofollow’ target=’_blank’>$author</a>保存,就ok了。

  注意:修改代码前最好将comment-template.php文件备份,改错后还能覆盖恢复。
  不过用代码修改就是有一个问题,就是升级WordPress后要重新修改代码。
这是如何让WordPress评论中的链接在新窗口打开,如果想要评论者的链接也在新窗口打开请看《如何让WordPress中评论者的链接在新窗口中打开

本文共 32 个回复

  • türsprechanlage von goliath 2019/01/24 06:52

    WOW just what I was looking for. Came here by searching for 如何让WordPress评论中的链接在新窗口打开手机小菜的博客

  • haircut 2019/01/21 15:53

    Thanks for sharing your thoughts on 如何让WordPress评论中的链接在新窗口打开手机小菜的博客. Regards

  • 北京赛车pk10开奖网站 2019/01/16 18:20

    ds7747.com、北京赛车pk10开奖、北京赛车pk10开奖直播、北京赛车pk10开奖网站、北京赛车pk10开奖网站

  • Harlan 2019/01/14 05:32

    WOW just what I was searching for. Came here by searching for 如何让WordPress评论中的链接在新窗口打开手机小菜的博客

  • cheap flights to san diego 2019/01/11 22:20

    I think that what you published was actually very logical. But, consider this, suppose you added a little content? I mean, I don't wish to tell you how to run your website, however what if you added something that makes people want more? I mean 如何让WordPress评论中的链接在新窗口打开 | 手机小菜的博客 is kinda vanilla. You ought to look at Yahoo's front page and watch how they create article titles to grab people to open the links. You might add a video or a related pic or two to grab people interested about everything've got to say. Just my opinion, it would make your posts a little bit more interesting.

  • Alarmanlage Meinz 2019/01/10 08:33

    Thanks for finally talking about >如何让WordPress评论中的链接在新窗口打开 | 手机小菜的博客 <Liked it!

  • Big Bash Cricket Betting Tips 2019/01/09 00:55

    Everything composed was very reasonable. However, what about this? suppose you were to write a awesome title? I ain't saying your information is not solid, but suppose you added something that makes people desire more? I mean 如何让WordPress评论中的链接在新窗口打开 | 手机小菜的博客 is a little vanilla. You should look at Yahoo's front page and watch how they create news headlines to get viewers interested. You might add a video or a related pic or two to get people excited about everything've got to say. In my opinion, it might bring your blog a little livelier.

1 2

发表评论