notepad++
wordpress
禁止蜘蛛抓取replytocom 在网站根目录下的robots.txt中,加入以下规则,禁止搜索引擎抓取含有 ?replytocom= 的链接:User-agent: *Disallow: /*?replytocom=
给链接添加nofollow 此方法效果跟上面的差不多。我们可以在当前主题的functions.php中添加以下PHP代码,这样就给回复按钮链接添加rel="nofollow"属性,同样可以告诉搜索引擎不要抓取此链接:add_filter('comment_reply_link', 'add_nofollow', 420, 4);function add_nofollow($link, $args, $comment, $post){ return str_replace("href=", "rel='nofollow' href=", $link);}
直接删除replytocom链接 有些搜索引擎并不遵守robots.txt规则或nofollow属性,会照样抓取replytocom链接。我们可以在当前主题的functions.php中添加以下PHP代码,这样链接A就会直接被替换成了#comment-评论id,搜索引擎会自动忽略带 # 号的链接,并且你的网站再也不存在replytocom链接了:add_filter('comment_reply_link', 'add_nofollow', 420, 4);function add_nofollow($link, $args, $comment, $post){ return preg_replace( '/href=\'(.*(\?|&)replytocom=(\d+)#respond)/', 'href=\'#comment-$3', $link );}
如果你不喜欢 #comment-评论id 这样的链接,可以将第4行代码中的 #comment-$3 改成你自己喜欢的链接。