方法一:通过插件来实现:(这个没用过)
我爱水煮鱼的“Comments Link Redirect“插件
下载地址:
方法二:在主题文件夹functions.php文件中用代码实现:(下面是适用于我所使用的主题,大多主题应该只需第二步)
对于iNove与Poetry主题:
①在主题文件夹functions.php文件中查找:
<a id="commentauthor-<?php comment_ID() ?>" class="url" href="
在
href="
后面加上
<?php bloginfo('url'); ?>/?r=
②在主题文件夹functions.php文件中添加如下代码:
//评论者链接跳转_Start 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: ".get_bloginfo('url').""); exit; } } } //评论者链接跳转_End
③在wordpress网站根目录robots.txt中添加如下语句:
Disallow: /?r=*
①首先修改WP默认的评论链接,在主题functions.php文件中加入以下代码:
/*yg_redirect_link*/ function yg_redirect_link($redirect_link = ''){ $redirect_link=str_replace('href="', 'target="_blank" href="'.get_bloginfo('template_url').'/visit.php?', $redirect_link); $redirect_link=str_replace("href='", "target='_blank' href='".get_bloginfo('template_url')."/visit.php?", $redirect_link); return $redirect_link; } add_filter('get_comment_author_link', 'yg_redirect_link', 5);
②将visit.php文件放入主题目录,visit.php文件内容如下:
<?php //add visit.php? before the link you need to redirect header("location: ".$_SERVER['QUERY_STRING']); ?>
③在wordpress网站根目录robots.txt中添加如下语句:
Disallow: /wp-content
@夜光
还是不理解 ?r= 变成类似于这样 搜索引擎会识别为是自己的网站收录 额 是这样吧 但是访问了还是跳转到r=后面的?
是对收录好?
@moper
都加了?r=就可以在robots里Disallow了呀…
@夜光
哦……这样 汗 谢谢哈