做网站难免会多多少少地采集一些同类网站的一些比较优质的文章,尤其是通过采集软采集过来的文章,可以在弄到自己的时候,不知不觉地在文章中留下了对方文章中的有意做的链接,如果对方网站被搜索引擎惩罚的话,也会连累我们。怎么办呢,简单啊,直接去掉这些危害的链接呗。怎么去呢?不可能一个一个地去删除吧,如果上千篇文章,那还不要累死我们呀。其实,这里有一个非常简单地方法,就是直接在主题添加这样的功能,让网站自动去删除这些外链。方法是在你正在使用的wordpress主题的functions.php文件中添加如下代码:
add_filter( 'the_content', 'v7v3_seo_wl');
function v7v3_seo_wl( $content ) {
$regexp = "<a\s[^>]*href=(\"??)([^\" >]*?)\\1[^>]*>";
if(preg_match_all("/$regexp/siU", $content, $matches, PREG_SET_ORDER)) {
if( !empty($matches) ) {$srcUrl = get_option('siteurl');
for ($i=0; $i < count($matches); $i++)
{$tag = $matches[$i][0];
$tag2 = $matches[$i][0];
$url = $matches[$i][0];$noFollow = '';
$pattern = '/target\s*=\s*"\s*_blank\s*"/';
preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
if( count($match) < 1 )
$noFollow .= ' target="_blank" ';$pattern = '/rel\s*=\s*"\s*[n|d]ofollow\s*"/';
preg_match($pattern, $tag2, $match, PREG_OFFSET_CAPTURE);
if( count($match) < 1 )
$noFollow .= ' rel="nofollow" ';$pos = strpos($url,$srcUrl);
if ($pos === false) {
$tag = rtrim ($tag,'>');
$tag .= $noFollow.'>';
$content = str_replace($tag2,$tag,$content);
}
}
}
}$content = str_replace(']]>', ']]>', $content);
return $content;
}
通过上面这段代码,我们就不用再怕复制采集别人网站的文章时会留不利于我们网站的外链了。当然,如果对方的网站是一个比较好的网站,能留,我们还是给对方留上一些这样的链接。