WordPress 文章评论添加外链跳转效果既美观又可避免权重流失,这个简单的 SEO 优化的确是一个不错的功能,纯手工修改源代码适合对源代码有一定经验的朋友,不需要安装插件内链跳转链接美观,荒岛本次带来 WordPress 文章评论外链转内链跳转的教程,只要将下面的代码添加到主题的「functions.php」文件即可。
// 荒岛一座藏有宝藏的小岛
function comment_author_link_go($content){
preg_match_all('/\shref=(\'|\")(http[^\'\"#]*?)(\'|\")([\s]?)/',$content,$matches);
if($matches){
foreach($matches[2] as $val){
if(strpos($val,home_url())===false){
$rep = $matches[1][0].$val.$matches[3][0];
$go = '"'. $val .'" rel="external nofollow" target="_blank"';
$content = str_replace("$rep","$go", $content);
}
}
}
return $content;
}
add_filter('comment_text','comment_author_link_go',99);
add_filter('get_comment_author_link','comment_author_link_go',99);
宝藏内容来自荒岛-https://x-imagine.com/wordpress-article-comment-external-link-to-internal-link-jump.html宝藏内容来自荒岛-https://x-imagine.com/wordpress-article-comment-external-link-to-internal-link-jump.html 请按「Ctrl+D」收藏荒岛分享给好友,如您发现本文教程或宝藏链接已失效,请联系站长修正!
荒岛公众号
扫一扫关注
HDsoft27
公众号ID已复制,前往微信关注...
荒岛哔哩姬
扫一扫关注
ximagine
哔哩姬ID已复制,前往B站关注...











