WordPress更改评论者链接为站内链接
本文章来给各位同学介绍关于如何处理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' ). '/?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: http://www.phpfensi.com" ); exit ; } } }在网站根目录下的robots.txt文件中添加以下代码,用来屏蔽搜索引擎收录重定向后的网址.
Disallow: /?r=*再来看看前台评论者的链接吧,都变成如下形式了
http://www.你的连接.com/?r=http://www.phpfensi.com
但如果你的博客使用的是多说插件,那以上所有写的东西都是废话,没办法对多说里的评论起作用.
直接给WordPress评论连接加上nofollow功能
找到wordpress的functions.php(wwwrootwp-contentthemesConcisePro1.3),然后在其中添加以下代码,保存上传即可,代码如下:
//评论加Nofollow function add_nofollow_to_comments_popup_link(){ return ' rel="nofollow" ' ; } add_filter( 'comments_popup_link_attributes' , 'add_nofollow_to_comments_popup_link' );顺便优化以下,要加的地方有两个,一个是评论者的链接,还有就是那个[回复]这也是个链接,代码如下:
//为评论者添加nofollow属性 function add_nofollow_to_comments_popup_link(){ return 'rel="nofollow" ' ; } add_filter( 'comments_popup_link_attributes' , 'add_nofollow_to_comments_popup_link' ); //为评论回复链接加nofollow属性 add_filter( 'comment_reply_link' , 'add_nofollow_to_replay_link' ); function add_nofollow_to_replay_link( $link ){ return str_replace ( '")' > ', ' ") ' rel=' nofollow '>' , $link ); }查看更多关于WordPress更改评论者链接为站内链接 - WordPress的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did8607