用代码重写wordpress留言评论者的连结网址

seo没有很复杂,基本上很简单。
只是有一些小要点要留意。
就是当留言评论的内容,含有网址或连结时,容易让「搜寻引擎」的重心,转向外部连结。
因此我们可以用代码改变评论留言里面的内容。
变成这样http://dhamma.com.tw/?r=http://amitabhabuddhaya.com.tw/
具体做法,开启主题的functions.php贴入以下代码
[cc lang="php"] //用代码重写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="/zh-CN/, 'href="'.get_option('home').'/?r=', $text);$text=str_replace("href= '", "href='/zh-CN/.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;}}}//让留言评论网址或连结加入nofollow属性add_filter('comment_text', 'auto_nofollow');function auto_nofollow($content) {//return stripslashes(wp_rel_nofollow($content));return preg_replace_callback('/]+/', 'auto_nofollow_callback', $content);}function auto_nofollow_callback($matches) {$link = $matches[0];$site_link = get_bloginfo('url');if (strpos($link, 'rel' ) === false) {$link = preg_replace("%(href=S(?!$site_link))%i", 'rel="nofollow" $1', $link);} elseif (preg_match("%href =S(?!$site_link)%i", $link)) {$link = preg_replace('/rel=S(?!nofollow)S*/i', 'rel="nofollow"', $link); }return $link;}[/cc]

评论 (0)

此处尚未发表评论

留言

  1. 以游客身份发表评论。注册登入到您的帐户。
附件 (0/ 3)
分享您的位置