A-A+
wordpress评论链接转为内链转跳的方法
wordpress 默认是有评论链接的,并且添加了 nofollow 属性来防止垃圾链接,链接的方式是 _blank,直接打开新窗口,这样感觉还是对站点有一定的影响,如何彻底的屏蔽掉蜘蛛抓取这些链接呢,其实我们完全可以把这些评论转换成站点链接,然后再用 robots.txt 的方式彻底屏蔽掉这些链接。
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').'/xiariboke_to.php?v7v3=', $text); $text=str_replace("href='", "href='".get_option('home')."/xiariboke_to.php?v7v3=", $text); return $text; }
将这些代码加入到主题 functions.php 文件中,然后在根目录下建立一个 xiariboke_to.php 的文件并写入如下的代码:
<html> <head> <meta http-equiv=Content-Type content="text/html;charset=utf-8"> <title>xiariboke.net转跳页</title> <meta name="robots" content="noindex,nofollow"> <meta http-equiv="refresh" content="3;url=<?php $url=$_GET['xiariboke']; echo htmlspecialchars($url);?>"> <style> body {background:#F7F7F7} p {background:#FFFFCC;border:1px solid #FFCC00;font-size:14px;letter-spacing: 1px;line-height:2;margin:auto;overflow:hidden;padding:15px 30px;width:550px} span {color:red;border-bottom:1px solid} </style> </head> <body> <p> 请稍等!3秒后转跳转至:<span><?php $url=$_GET['xiariboke']; echo htmlspecialchars($url);?></span><br><br> 您也可以 <a href="<?php $url=$_GET['xiariboke']; echo htmlspecialchars($url);?>">点击此处</a> 立即打开链接, 或者返回 <a href="https://www.xiariboke.net/"> 夏日博客</a> 继续浏览其它内容. </p> </body> </html>
然后在 robots.txt 文件中彻底屏蔽掉 xiariboke_to.php 的链接,代码如下:
Disallow: /v7v3_to.php?*
这样自己的博客就已经将 wordpress 评论的直接链接变成了站内内链的跳转形式了。
文章不错,挺好 。
会打击留言积极性的