wordpress去除评论者的链接

十度 wordpress 2015年12月20日 收藏

如果你使用wordpress建站,并且已经有了一定的访问量,你就会感觉有大量的人在你文章发大量的评论,而且评论质量很差,其真实目的就是为了发外链。虽然链接上加上了 no follow 标签,但我们还是希望文章的评论是访问者的真正感想。那如何去除wordpress中评论作者的链接呢?方法如下:
1、打开wp-includes/comment-template.php文件,查找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);
}

2、修改代码
将代码:

$return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";  //需要修改的地方

修改为:

$return = $author;

3、最终的代码如下:

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 = $author;  //修改后
	return apply_filters('get_comment_author_link', $return);
}

OK!!修改保存传到你的空间上看看效果吧!!
ps:如果wordpress升级,wp-includes/comment-template.php有可能被重新覆盖,需要重新按以上方法修改。