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

上次我们说到了《如何让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”>$author</a>”;
return apply_filters(‘get_comment_author_link’, $return);
}
因版本不同代码可能会有些差异,小菜用的是3.42.
找到
<a href=”$url” rel=”external nofollow”>$author</a>
在href=’$url’ 后添加target=’_blank’ ,就变成了

href='$url' target='_blank' rel='external nofollow' class='url'

再加上上次修改的如何让WordPress评论中的链接在新窗口打开添加的代码,最终就是
“<a href=’$url’ target=’_blank’ rel=’external nofollow’ class=’url’ target=’_blank’>$author</a>”;

注意:修改代码前最好将comment-template.php文件备份,改错后还能覆盖恢复。

不过用代码修改就是有一个问题,就是升级WordPress后要重新修改代码。


关于小菜

有认识我的友友吗?

4 comments:

回复 Youth.霖 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注