设计笔记

  • 首页
  • 作品
  • 代码
  • 随笔
  • 关于博主
    • 豆瓣书影
  • 友情链接
  • 文章归档
  • 榜上有名
  • RSS Feed
  • GitHub
  • Twitter
  • Link

喜欢这款主题

抢先体验

新窗口打开留言者的链接

  • Tokin
  • 2012-08-18
  • 1

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

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

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

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”>,保存。

© 2025 设计笔记
Theme by Wing
  • {{ item.name }}
  • {{ item.name }}