WordPress设置评论链接重定向跳转
首先:在主题目录下的函数模板
| 代码如下 | 复制代码 |
| //comments link redirect // 以下是我添加的wordpress设置评论链接重定向跳转 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']; $host = $_SERVER['HTTP_HOST']; if($redirect){ if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){ header("Location: $redirect#form:$host"); exit; } else { header("Location: $redirect#form:$host"); exit; } } } |
|
//以上是我添加的wordpress设置评论链接重定向跳转
这样URL跳转是基本完成了。接下来就是要实现超链接在新窗口中打开了。打开wp-includes目录下的comment-template.php文件,到第147行左右的get_comment_author_link()函数(也就是function get_comment_author_link( $comment_ID = 0 )),在第155行else $return 这行标签里加入target=‘_blank’属性,修改后上传即可。完整的代码贴上来:
| 代码如下 | 复制代码 |
|
function get_comment_author_link( $comment_ID = 0 ) { if ( empty( $url ) || 'http://***' == $url ) |
|
根据下面图里在第一句的nofollow后面增加一个target=”_blank”。
设置评论链接Nofollow属性
wordpress的评论链接添加Nofollow属性和设置URL跳转,来避免垃圾评论,垃圾链接对自己博客质量的影响。你可以通过下面在 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: https://www.111cn.net/"); //这个链接换成你自己网站 exit; } |
|
以上就是怎样给wordpress的评论链接添加Nofollow属性和设置评论链接重定向跳转的方法
模拟极限越野
模拟极限越野开着大巴在各种奇葩路况里送乘客。山路弯道多得让人
模拟火车
模拟火车让你当回真正的火车司机,得先学会看信号灯、操作控制杆
可口的披萨美味的披萨
可口的披萨美味的披萨带您体验经营一家披萨店的乐趣。游戏画风温
定制虚拟偶像最新版
定制虚拟偶像最新版是一款超级经典有趣的日本模拟装扮类型的手游
病娇模拟器手机版正版(yandere simulator)
病娇模拟器最新版手游是一款萌妹二次元模拟游戏,玩家在游戏中可