您的位置:首页 > 其它

wordpress小技巧:评论链接转为内链转跳的方法

2013-07-10 11:07 363 查看
大家都知道的,wordpress站点中访客留言后,如果访客留下了站点链接的话,wordpress默认是会以描文本的形式给访客添加一个外链的。虽然wordpress默认的都会给链接加上nofollow属性来防止垃圾链接的,但是这样毕竟还是会对网站造成影响的,那么怎样来完全禁止蜘蛛爬取这些链接呢?其实我们可以将这些评论链接转换成站内链接然后使用robots.txt来完全屏蔽这些链接。下面小V就来教大家如何实现评论链接转为内链转跳的方法。
1、首先打开当前wordpress主题的functions.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').'/v7v3_to.php?v7v3=', $text);
   $text=str_replace("href='", "href='".get_option('home')."/v7v3_to.php?v7v3=", $text);
   return $text;
}
2、在网站根目录新建一个v7v3_to.php文件并写入以下代码:
<html>
<head>
   <meta http-equiv=Content-Type content="text/html;charset=utf-8">
   <title>v7v3.com转跳页</title>
   <meta name="robots" content="noindex,nofollow">
   <meta http-equiv="refresh" content="3;url=<?php $url=$_GET['v7v3']; 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['v7v3']; echo htmlspecialchars($url);?></span><br><br>
       您也可以 <a href="<?php $url=$_GET['v7v3']; echo htmlspecialchars($url);?>">点击此处</a> 立即打开链接, 或者返回 <a href="http://www.v7v3.com/"> 维7维3</a> 继续浏览其它内容.
   </p>
</body>
</html>
然后在robots.txt文件中写入以下代码:
Disallow: /v7v3_to.php?*
其实不修改robots.txt也没关系,因为小V在转跳页面已经用
<meta name="robots" content="noindex,nofollow">
标签将页面进行了抓取屏蔽。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: