|
今天要介绍的方法是直接在主题文件functions.php添加下面的代码后,同时实现评论作者链接地址重定向和在新窗口打开两个功能,这样就不会受wordpress版本更新的影响了。
//访客链接新窗口打开
function comment_author_link_window()
{
global $comment;
$url = get_comment_author_url();
$author = get_comment_author();
$home = get_option('home');
if ( empty( $url ) || 'http://' == $url )
$return = $author;
else
$return = "<a href='$home?url=$url' rel='external nofollow' target='_blank'>$author</a>";
return $return;
}
add_filter('get_comment_author_link', 'comment_author_link_window');
//开启评论链接地址重写
function redirect_comment_link()
{
$redirect = $_GET['url'];
if($redirect){
if(strpos($_SERVER['HTTP_REFERER'],get_option('home')) !== false){
header("Location: $redirect");
exit;
} else {
header("Location:".get_option('home'));
exit;
}
}
}
add_action('init', 'redirect_comment_link');
注意事项:添加这些代码之前,检查一下自己的主题中是否自带了评论链接新窗口打开的代码,如果有的话,需要先去掉原来的那个,不然的话可能会报错。
原创文章转载请注明出处: : http://www.dreamxyt.net/541.html | 梦想象牙塔