我是不太赞成直接去掉评论者的链接的,就是因为有了评论着的链接才可能产生回访的效果,wordpress博客系统主题中大都有评论的链接,偶尔遇到一些权重较大的博客直接去掉了评论者的链接,再有就是百度的蜘蛛会爬取链接的内容,从而导致有重复收录内容的出现,这对于优化是很不好的,下面来看一下如何去掉评论者的链接,方法代码如下:,[code lang="php"]
global $wpdb;
$sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
comment_post_ID, comment_author, comment_date_gmt, comment_approved,
comment_type,comment_author_url,
SUBSTRING(comment_content,1,14) AS com_excerpt
FROM $wpdb->comments
LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
$wpdb->posts.ID)
WHERE comment_approved = "1" AND comment_type = "" AND
post_password = ""
ORDER BY comment_date_gmt DESC
LIMIT 10";
$comments = $wpdb->get_results($sql);
$output = $pre_HTML;
foreach ($comments as $comment) {
$output .= "\n

  • ".strip_tags($comment->comment_author)
    .":" . " ID) .
    "#comment-" . $comment->comment_ID . "\" title=\"on " .
    $comment->post_title . "\">" . strip_tags($comment->com_excerpt)
    ."
  • ";
    }
    $output .= $post_HTML;
    echo $output;?>
    [/code],这段代码是直接去掉了评论者的链接,如果不想要评论链接,直接使用这段代码就可以了,因为去掉了链接,百度蜘蛛也就不会爬取了。,另外,当我们的站点已经被搜索引擎抓取了许多的评论内容的时候就要把这些评论链接重定向,屏蔽掉才行,在 functions.php 文件中加入如下的代码:,[code lang="php"]
    //评论链接重定向
    add_filter("get_comment_author_link", "add_redirect_comment_link", 5);
    add_filter("comment_text", "add_redirect_comment_link", 99);
    function add_redirect_comment_link($text = ""){
    $text=str_replace("href="", "href="".get_option("home")."/?r=", $text);
    $text=str_replace("href="", "href="".get_option("home")."/?r=", $text);
    return $text;
    }
    add_action("init", "redirect_comment_link");
    function redirect_comment_link(){
    $redirect = $_GET["r"];
    if($redirect){
    if(strpos($_SERVER["HTTP_REFERER"],get_option("home")) !== false){
    header("Location: $redirect");
    exit;
    }
    else {
    header("Location: https://www.xiariboke.net/");
    exit;
    }
    }
    }
    [/code],在网站根目录下的robots.txt文件中添加以下代码,用来屏蔽搜索引擎收录重定向后的网址,Disallow: /?r=*,这样当我们再来看前台的时候,所有的评论链接都已经重定向到了 xiariboke.net了,如下形式:,https://www.xiariboke.net/?r=http://www.xxx.com,

    我是不太赞成直接去掉评论者的链接的,就是因为有了评论着的链接才可能产生回访的效果,wordpress博客系统主题中大都有评论的链接,偶尔遇到一些权重较大的博客直接去掉了评论者的链接,再有就是百度的蜘蛛会爬取链接的内容,从而导致有重复收录内容的出现,这对于优化是很不好的,下面来看一下如何去掉评论者的链接,方法代码如下:

    [code lang="php"]
    global $wpdb;
    $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
    comment_post_ID, comment_author, comment_date_gmt, comment_approved,
    comment_type,comment_author_url,
    SUBSTRING(comment_content,1,14) AS com_excerpt
    FROM $wpdb->comments
    LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
    $wpdb->posts.ID)
    WHERE comment_approved = "1" AND comment_type = "" AND
    post_password = ""
    ORDER BY comment_date_gmt DESC
    LIMIT 10";
    $comments = $wpdb->get_results($sql);
    $output = $pre_HTML;
    foreach ($comments as $comment) {
    $output .= "\n

  • ".strip_tags($comment->comment_author)
    .":" . " ID) .
    "#comment-" . $comment->comment_ID . "\" title=\"on " .
    $comment->post_title . "\">" . strip_tags($comment->com_excerpt)
    ."
  • ";
    }
    $output .= $post_HTML;
    echo $output;?>
    [/code]

    这段代码是直接去掉了评论者的链接,如果不想要评论链接,直接使用这段代码就可以了,因为去掉了链接,百度蜘蛛也就不会爬取了。

    另外,当我们的站点已经被搜索引擎抓取了许多的评论内容的时候就要把这些评论链接重定向,屏蔽掉才行,在 functions.php 文件中加入如下的代码:

    [code lang="php"]
    //评论链接重定向
    add_filter("get_comment_author_link", "add_redirect_comment_link", 5);
    add_filter("comment_text", "add_redirect_comment_link", 99);
    function add_redirect_comment_link($text = ""){
    $text=str_replace("href="", "href="".get_option("home")."/?r=", $text);
    $text=str_replace("href="", "href="".get_option("home")."/?r=", $text);
    return $text;
    }
    add_action("init", "redirect_comment_link");
    function redirect_comment_link(){
    $redirect = $_GET["r"];
    if($redirect){
    if(strpos($_SERVER["HTTP_REFERER"],get_option("home")) !== false){
    header("Location: $redirect");
    exit;
    }
    else {
    header("Location: https://www.xiariboke.net/");
    exit;
    }
    }
    }
    [/code]

    在网站根目录下的robots.txt文件中添加以下代码,用来屏蔽搜索引擎收录重定向后的网址

    Disallow: /?r=*

    这样当我们再来看前台的时候,所有的评论链接都已经重定向到了 xiariboke.net了,如下形式:

    https://www.xiariboke.net/?r=http://www.xxx.com

    ,

    我是不太赞成直接去掉评论者的链接的,就是因为有了评论着的链接才可能产生回访的效果,wordpress博客系统主题中大都有评论的链接,偶尔遇到一些权重较大的博客直接去掉了评论者的链接,再有就是百度的蜘蛛会爬取链接的内容,从而导致有重复收录内容的出现,这对于优化是很不好的,下面来看一下如何去掉评论者的链接,方法代码如下:

    [code lang="php"]
    global $wpdb;
    $sql = "SELECT DISTINCT ID, post_title, post_password, comment_ID,
    comment_post_ID, comment_author, comment_date_gmt, comment_approved,
    comment_type,comment_author_url,
    SUBSTRING(comment_content,1,14) AS com_excerpt
    FROM $wpdb->comments
    LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID =
    $wpdb->posts.ID)
    WHERE comment_approved = "1" AND comment_type = "" AND
    post_password = ""
    ORDER BY comment_date_gmt DESC
    LIMIT 10";
    $comments = $wpdb->get_results($sql);
    $output = $pre_HTML;
    foreach ($comments as $comment) {
    $output .= "\n

  • ".strip_tags($comment->comment_author)
    .":" . " ID) .
    "#comment-" . $comment->comment_ID . "\" title=\"on " .
    $comment->post_title . "\">" . strip_tags($comment->com_excerpt)
    ."
  • ";
    }
    $output .= $post_HTML;
    echo $output;?>
    [/code]

    这段代码是直接去掉了评论者的链接,如果不想要评论链接,直接使用这段代码就可以了,因为去掉了链接,百度蜘蛛也就不会爬取了。

    另外,当我们的站点已经被搜索引擎抓取了许多的评论内容的时候就要把这些评论链接重定向,屏蔽掉才行,在 functions.php 文件中加入如下的代码:

    [code lang="php"]
    //评论链接重定向
    add_filter("get_comment_author_link", "add_redirect_comment_link", 5);
    add_filter("comment_text", "add_redirect_comment_link", 99);
    function add_redirect_comment_link($text = ""){
    $text=str_replace("href="", "href="".get_option("home")."/?r=", $text);
    $text=str_replace("href="", "href="".get_option("home")."/?r=", $text);
    return $text;
    }
    add_action("init", "redirect_comment_link");
    function redirect_comment_link(){
    $redirect = $_GET["r"];
    if($redirect){
    if(strpos($_SERVER["HTTP_REFERER"],get_option("home")) !== false){
    header("Location: $redirect");
    exit;
    }
    else {
    header("Location: https://www.xiariboke.net/");
    exit;
    }
    }
    }
    [/code]

    在网站根目录下的robots.txt文件中添加以下代码,用来屏蔽搜索引擎收录重定向后的网址

    Disallow: /?r=*

    这样当我们再来看前台的时候,所有的评论链接都已经重定向到了 xiariboke.net了,如下形式:

    https://www.xiariboke.net/?r=http://www.xxx.com

    最后修改:2025 年 09 月 10 日
    如果觉得我的文章对你有用,请随意夸赞