现在写博客的人越来越多,开个人独立博客的也越来越多。有的人是为了通过博客赚钱,有的人是用来分享交流技术,有的人就纯粹是记录个人生活,分享个人的兴趣爱好而已;不管怎样,虽然开通个人博客的目的不同,但是有一点是相同的,就是希望把自己认为有价值的东西同网络上的志同道合的人分享交流。
独立博客基本上都可以给人评论,但是随着网络营销的人,就是做网络推广的,所谓的seo,网络水军什么的童鞋太多了,所以经常在博客上留下所谓的“垃圾评论”,这个仁者见仁智者见智吧。当然这与我们写博客的初衷有点背道而驰,我们还是想评论是真正对自己写的文字发表观点,学习交流。所以,很多人都给自己的博客评论链接加Nofollow属性并且设置URL跳转链接。
给wordpress的评论链接添加Nofollow属性和设置评论链接重定向跳转可以通过插件和通过修改robots.txt来做到,但是对于插件和robots.txt文件修改这两种方法,我都认为不是很好,对网站速度和搜索引擎都不是很好,所以下面介绍第三种方法来解决怎样实现wordpress的评论链接添加Nofollow属性和设置URL跳转,来避免垃圾评论,垃圾链接对自己博客质量的影响。
示例链接https://www.qcgzxw.cn/go.php?code.qcgzxw.cn
效果截图

具体做法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
//评论链接url跳转 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="',%20'target="_blank" href="'.get_option('home').'/go.php?url=', $text ); $text=str_replace("href='", "target='_blank'href='".get_option('home')."/go.php?url=", $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.qcgzxw.cn/"); exit; } } } //结束 |
1.直接将上面的代码插入到functions.php文件。
2.然后上传跳转页面代码go.php至网站根目录
新建个go.php文件然后将下面的代码写进去之后上传到网站根目录
不会的可以直接下载文章底部的文件解压后上传至根目录
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
<?php $t_url = preg_replace('/^url=(.*)$/i','$1',$_SERVER["QUERY_STRING"]); if(!empty($t_url)) { preg_match('/(http|https):\/\//',$t_url,$matches); if($matches){ $url=$t_url; $title='页面加载中,请稍候...'; } else { preg_match('/\./i',$t_url,$matche); if($matche){ $url='http://'.$t_url; $title='页面加载中,请稍候...'; } else { $url='https://www.qcgzxw.cn/'; $title='参数错误,正在返回首页...'; } } } else { $title='参数缺失,正在返回首页...'; $url='https://www.qcgzxw.cn/'; } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="refresh" content="1;url='<?php echo $url;?>';"> <title><?php echo $title;?></title> <style> body{background:#000}.loading{-webkit-animation:fadein 2s;-moz-animation:fadein 2s;-o-animation:fadein 2s;animation:fadein 2s}@-moz-keyframes fadein{from{opacity:0}to{opacity:1}}@-webkit-keyframes fadein{from{opacity:0}to{opacity:1}}@-o-keyframes fadein{from{opacity:0}to{opacity:1}}@keyframes fadein{from{opacity:0}to{opacity:1}}.spinner-wrapper{position:absolute;top:0;left:0;z-index:300;height:100%;min-width:100%;min-height:100%;background:rgba(255,255,255,0.93)}.spinner-text{position:absolute;top:50%;left:50%;margin-left:-90px;margin-top: 2px;color:#BBB;letter-spacing:1px;font-weight:700;font-size:36px;font-family:Arial}.spinner{position:absolute;top:50%;left:50%;display:block;margin-left:-160px;width:1px;height:1px;border:25px solid rgba(100,100,100,0.2);-webkit-border-radius:50px;-moz-border-radius:50px;border-radius:50px;border-left-color:transparent;border-right-color:transparent;-webkit-animation:spin 1.5s infinite;-moz-animation:spin 1.5s infinite;animation:spin 1.5s infinite}@-webkit-keyframes spin{0%,100%{-webkit-transform:rotate(0deg) scale(1)}50%{-webkit-transform:rotate(720deg) scale(0.6)}}@-moz-keyframes spin{0%,100%{-moz-transform:rotate(0deg) scale(1)}50%{-moz-transform:rotate(720deg) scale(0.6)}}@-o-keyframes spin{0%,100%{-o-transform:rotate(0deg) scale(1)}50%{-o-transform:rotate(720deg) scale(0.6)}}@keyframes spin{0%,100%{transform:rotate(0deg) scale(1)}50%{transform:rotate(720deg) scale(0.6)}} </style> </head> <body> <div class="loading"> <div class="spinner-wrapper"> <span class="spinner-text">页面加载中,请稍候...</span> <span class="spinner"></span> </div> </div> </body> </html> |
设置好之后,别人评论区的网站链接就是通过你的页面跳转出去的,有利于seo哦。
如果还有什么不懂的可以在下面留言,24h在线解答哦
Yesterday, while I was at work, my sister stole my iPad and
tested to see if it can survive a 40 foot drop, just so she can be a youtube sensation. My apple ipad is now
broken and she has 83 views. I know this is completely off topic but I had to
share it with someone!
I’s sorry to hear that your ipad was broken!
Mabey she would pay for it!
For most up-to-date news you have to go to see world wide web and on the web I found this site as a best web site
for hottest updates.
Thanks!