设计笔记
代码 约 3 分钟阅读

新窗口打开留言者的链接

在你网站留言的用户,如果填写连接的话,点击后你会发现,链接会在本窗口打开,如果想让来你网站的用户多逗留,这个细节一定要注意,让这些链接在新窗口打开。

没有什么技术含量可言,网上早有高手支招,于是自己研究了下代码,完美解决,分享一下:

一般主题都可以这样修改:

1、打开wordpress目录的下/wp-includes/comment-template.php文件。

2、找到下面这行代码:$return = “<a href=’$url’ rel=’external nofollow’ class=’url’>$author</a>”;

3、在标签中添加target属性,值为\_blank(在新窗口中打开链接),保存。

即代码修改为:$return = “<a href=’$url’ rel=’external nofollow’ class=’url’ target=’\_blank’>$author</a>”;

此方法是适用于大部分主题,同时wp-recentcomments插件上的留言者链接也可以在新窗口中打开。但是有些主题就不行,不过同样也可以更改。

1、打开插件目录下的functions.php文件。找到: <?php if (get_comment_author_url()) : ?> <a id=”commentauthor-<?php comment_ID() ?>” class=”url” href=”<?php comment_author_url() ?>” rel=”external nofollow”>

2、同样添加target=”\_blank”,改为 <a id=”commentauthor-<?php comment\_ID() ?>” class=”url” href=”<?php comment_author_url() ?>” rel=”external nofollow” target=”\_blank”>,保存。