说明
之前分享过WordPress添加文章、评论外链GO转跳的教程。今天带来一个新的,相较于之前的,这次新增了将原链接用base64 将源链接加密,并且加上了 nofollow。
代码
首先,在主题文件中的functions.php添加以下代码
/*
*自动给文章的外部链接添加nofollow属性
*/
add_filter('the_content','web589_the_content_nofollow',999);
function web589_the_content_nofollow($content){
preg_match_all('/href="(http.*?)"/',$content,$matches);
if($matches){
foreach($matches[1] as $val){
if( strpos($val,home_url())===false )
$content=str_replace("href=\"$val\"", "rel=\"nofollow\" href=\"" . get_bloginfo('wpurl'). "/go.php?url=" .base64_encode($val). "\"",$content);
}
}
return $content;
}
之后再WordPress的根目录中新建一个go.php的文件,放入以下代码
效果

可以看到,转跳链接已经过baes64加密
看看在说。。
看看在说。。