纯代码实现WordPress给评论/内外链加一个跳转链接有利于SEO



 

图片[1]-纯代码实现WordPress给评论/内外链加一个跳转链接有利于SEO-卷生活九二零

把以下全部代码复制到你的模板函数 (functions.php)  注:模板不同,有些会是在:(functions-theme.php)

/*-----------------------------------------------------------------------------------*/
/* WordPress文章内外链添加go跳转
/ * https://www.juan920.com/73.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.juan920.com/73.html
/* WordPress评论者链接添加go跳转
/*-----------------------------------------------------------------------------------*/
function loper_redirect_comment_link($text = ''){
$text = str_replace('href="', 'href="'%20. 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);
支付宝扫码打赏 微信打赏

如果我的文章对你有帮助,欢迎移至上方按钮打赏

© 版权声明
THE END
点赞0
分享