WordPress文章外链和评论链接go跳转,经常看到一些博客点击外链跳转到其他网站上的时候都会有一个跳转页面,这跳转页面是很漂亮的,据说是有利于SEO,保护站点权重,拽立网,网上相关的源代码很多,只是代码使用的方法不太详细,对于很多新手小白可能并不友好,希望能够帮助新人快速地使用上这个跳转功能。
文章外链效果图:
评论链接效果图:
go跳转效果图:
直接把以下全部代码复制到你的模板函数 (functions.php)
文章内外链和评论链接go跳转代码:
/*-----------------------------------------------------------------------------------*/
/* WordPress文章内外链添加go跳转
/*-----------------------------------------------------------------------------------*/
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);
/*-----------------------------------------------------------------------------------*/
/* 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);
然后直接把【go.php】文件上传到你的主题目录里
我会把【gp.php】文件打包好,给你下载
提示:必须放到你的主题目录里就行了

版权声明:本站原创文章,于2018年08月12日,由 拽立网 发表,共 1576 字。
打赏



外链是网盘分享链接,等时间结束后自动跳转会在链接中插入&导致网址错误。不等待点击直接访问则无这个问题
@鱼的记忆: 可以把你的网站发来我看看,我自己使用是正常的,可能是有些代码冲突了
管理员回复可道云文件的分享链接
http://tiffany.cf/index.php?share/file&user=1&sid=VjqQTcDw
@鱼的记忆: 我用你的连接一样可以使用,不会出错什么的
管理员回复我通过不同的浏览器点击评论区发的链接,不点击立即前往。等5s过后自动跳转还是会出错