0
(0)

W3C标准认为链接新窗口打开属于强迫用户的行为,是不符合标准的,所以致wordpress3.0版本以后程序中所有链接均在本窗口打开,但是这样做,网站的pv会减少,跳出率会增高。特别是网站中最不应该跳出的评论链接,那么怎么设置使wordpress的评论者链接在新窗口打开呢?这里可以通过以下几种方式解决(因为不同网站的评论代码设置是不一样的)。

第一种方法:
1、在wordpress源程序wp-includes/comment-template.php中找到类似以下代码:

  1. function get_comment_author_link( $comment_ID = 0 ) {   
  2.     /** @todo Only call these functions when they are needed. Include in if… else blocks */  
  3.     $url    = get_comment_author_url( $comment_ID );   
  4.     $author = get_comment_author( $comment_ID );   
  5.   
  6.     if ( emptyempty$url ) || ‘http://’ == $url )   
  7.         $return = $author;   
  8.     else  
  9.         $return = “<a href=’$url’ rel=’external nofollow’ class=’url’>$author</a>”;   
  10.     return apply_filters(‘get_comment_author_link’, $return);   
  11. }  

2、在其中的一段代码:

  1. <a href=’$url‘ rel=’external nofollow’ class=’url’>$author</a>  

为以下代码:

  1. <a href=’$url‘ target=’_blank’ rel=’external nofollow’ class=’url’>$author</a>  

3、修改完成保存上传覆盖即可。

很遗憾,第一种方法我没有成功,因为我的评论文件使用的不是wordpress默认的评论文件,如果你也没有达到效果,请参照第二种方法解决:
第二种方法:
1、在wordpress源程序中wp-includes\formatting.php找到搜索以下代码:

  1. // Include parentheses in the URL only if paired   
  2. while ( substr_count( $url, ‘(‘ ) < substr_count( $url, ‘)’ ) ) {   
  3.     $suffix = strrchr$url, ‘)’ ) . $suffix;   
  4.     $url = substr$url, 0, strrpos$url, ‘)’ ) );   
  5. }   
  6.   
  7. $url = esc_url($url);   
  8. if ( emptyempty($url) )   
  9.     return $matches[0];   
  10.   
  11. return $matches[1] . “<a href=\”$url\” rel=\”nofollow\” target=\”_blank\”>$url</a>” . $suffix;   
  12.   

2、修改其中的链接代码:

  1. <a href=\“$url\” rel=\”nofollow\”>$url</a>  

为以下代码:

  1. <a href=\“$url\” rel=\”nofollow\” target=\”_blank\”>$url</a>  

3、保存上传覆盖。

真的想骂娘,折腾了半天竟然还是没有效果,原来想让自己的评论模块和别人不一样,付出的代价也是比别人大的,不过wordpress的魅力就在于此,如果你没有把自己折腾吐过,你根本不会明白成功后的那份喜悦(好像很像受虐狂 :smile: ),闲话少说,继续折腾。
第三种方法:
如果以上两个位置修改后依然没有效果,那就只能在一个位置了,当前主题的函数文件functions.php文件了,经过查找,确实在函数文件中存在以下一段代码:

  1. <a id=“commentauthor-<?php comment_ID() ?>” href=“<?php comment_author_url() ?>” rel=“external nofollow”>  

在a标签代码中添加上新窗口打开属性target=”_blank”即可,修改后的代码如下:

  1. <a target=“_blank” id=“commentauthor-<?php comment_ID() ?>” href=“<?php comment_author_url() ?>” rel=“external nofollow”>  

over!

声明:本站分享的WordPress主题/插件均遵循 GPLv2 许可协议(免费开源),相关介绍资料仅供学习参考,实际版本可能会因版本迭代或开发者调整而产生变化,如程序中涉及有第三方原创图像、设计模板、远程服务等内容,应获得作者授权后方可使用。本站不提供该程序/软件的产品授权与技术服务,亦不收取相关费用。