考慮到SEO的細節(jié),我們對于WordPress網站中的外部鏈接還是需要加上nofollow標簽的,如果手工加太麻煩,這里可以用代碼批量加上。
//批量給外部鏈接加上nofollow add_filter('the_content','the_content_nofollow',200); function the_content_nofollow($content){ preg_match_all('/href="(.*?)" rel="nofollow noopener" /',$content,$matches); if($matches){ foreach($matches[1] as $val){ if( strpos($val,home_url())===false ) //home_url為程序的url地址 $content=str_replace('href="'.$val.'" rel="nofollow noopener" rel="nofollow noopener" ', 'href="'.$val.'" rel="nofollow noopener" rel="nofollow noopener" rel="nofollow noopener" ', $content); } } return $content; }
評論