![图片[1]-WordPress给评论/内外链加一个跳转链接有利于SEO](https://www.ly522.com/wp-content/uploads/2018/08/1726-2-717x600.png)
由于遇到了一些评论留的有链接,链接有些直接指向了广告等,
所以啊让人挺反感,然后这篇文章就出来了
评论链接,这是有留了链接的,然后中间做了一次跳转
![图片[2]-WordPress给评论/内外链加一个跳转链接有利于SEO](https://www.ly522.com/wp-content/uploads/2018/08/1726-800x390.png)
然后蓝色字体的就是加了链接url,所以啊就加了一个跳转
![图片[3]-WordPress给评论/内外链加一个跳转链接有利于SEO](https://www.ly522.com/wp-content/uploads/2018/08/1726-1.png)
试用方法-(代码有修改精简-记磊博客正在使用)
把以下全部代码复制到你的模板函数 (functions.php) 注:模板不同,有些会是在:(functions-theme.php)
代码 文章内外链 我没加 只是加了评论,这个自行抉择
/*-----------------------------------------------------------------------------------*/
/* WordPress文章内外链添加go跳转
/ * https://www.ly522.com/1726.html
/*-----------------------------------------------------------------------------------*/
function loper_content_nofollow($content){
preg_match_all('/<a(.*?)href="(.*?)"(.*?)>/',$content,$matches);
if($matches){
foreach($matches[2] as $val){
if(strpos($val,'://')!==false && strpos($val,home_url())===false && !preg_match('/\.(jpg|jepg|png|ico|bmp|gif|tiff)/i',$val)){
$content=str_replace("href=\"$val\"", "href=\"".get_stylesheet_directory_uri()."/go.php?url=$val\" ",$content);
}
}
}
return $content;
}
add_filter('the_content','loper_content_nofollow',999);
/*-----------------------------------------------------------------------------------*/
/ * https://www.ly522.com/1726.html
/* WordPress评论者链接添加go跳转
/*-----------------------------------------------------------------------------------*/
function loper_redirect_comment_link($text = ''){
$text = str_replace('href="', 'href="' . get_stylesheet_directory_uri() . '/go.php?url=', $text);
$text = str_replace("href='", "href='" . get_stylesheet_directory_uri() . "/go.php?url=", $text);
return $text;
}
add_filter('get_comment_author_link', 'loper_redirect_comment_link', 5);
add_filter('comment_text', 'loper_redirect_comment_link', 99);
源码下载
链接: https://pan.baidu.com/s/1G6wNCPdSrgewPMSuUPh7dg 密码: pd2k
© 版权声明
THE END















![表情[qiang]-轻刻年轮](https://www.ly522.com/wp-content/themes/zibll/img/smilies/qiang.gif)
666
- 最新
- 最热
只看作者