这个和外链转内链的方法大同小异——都是利用函数钩子添加替换动作,将href属性替换为带有nofollow属性的形式。外链转内链的教程在本站这里
代码如下:
// 文章外链转内链并转入跳转页面 add_filter('the_content','goto_url',999); function goto_url($content){ preg_match_all('/rel="nofollow" target="_blank" href="(.*?)"/',$content,$matches); if($matches){ foreach($matches[1] as $val){ if( strpos($val,home_url())===false&&strpos($val,"javascript:void(0)")===false ) $content=str_replace("href=\"$val\"", "rel=\"nofollow\" target=\"_blank\" href=\"$val\"",$content); } } return $content; }
只不过改了一句代码而已。That's all.
本站文章除注明转载/出处外,均为本站原创或翻译。若要转载但请务必注明出处,尊重他人劳动成果。
转载请注明出处链接 : https://www.inlojv.com/4718.html