首页 » 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中评论者的链接在新窗口中打开

本文共 42 个回复

  • plenty of fish dating site 2019/06/22 11:07

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

  • gamefly free trial 2019/05/28 19:12

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

  • tinyurl.com 2019/04/12 14:36

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

  • barenAked ladies 2019/03/30 00:49

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

  • minecraft 2019/03/25 18:10

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

  • صيانة باناسونيك 2019/03/17 01:39

    I think what you said was actually very reasonable. However, consider this, suppose you were to write a killer post title? I mean, I don't want to tell you how to run your blog, however suppose you added something that grabbed a person's attention? I mean 如何让WordPress评论中的链接在新窗口打开 | 手机小菜的博客 is kinda boring. You could peek at Yahoo's home page and watch how they create news headlines to get people to open the links. You might add a video or a picture or two to get readers interested about what you've written. Just my opinion, it would bring your website a little livelier.

  • link 2019/03/09 14:05

    I think еverything published ade a ton of sense. Howеver, consiⅾer thіѕ, what if you added a littlе content? Iam not suggedting yօur ϲontent iss not solid., however suppose you added a post title to maybe grab people'ѕ attention? I mdan 如何让WordPress评论中的链接在新窗口打开 | 手机小菜的博客 іs kionda vanilla. Үoᥙ sһould glanjce аt Yahoo's home paɡe and see һow they ᴡrite article headlines t᧐ get viewers intеrested. Yοu miցht add a video or a related picture or two to get readers іnterested ɑbout everything've got to say. Jսѕt my opinion, іt woᥙld Ƅгing youг website a ⅼittle livelier.

  • ณัฐนินท์ ธรรมวิทย์เมธี 2019/03/04 05:37

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

  • toronto black soap 2019/03/04 00:56

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

  • esporte 2019/03/02 12:21

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

  • 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

发表评论