添加rel="external nofollow”
这是SEO优化站点文章常用方式之一。
参考蓝叶博客的文章,做个操作记录。
调整module.php
下面代码复制到module.php文件里
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<?php
function content_nofollow($log_content, $domain)
{
preg_match_all('/href="(.*?)"/', $log_content, $matches);
if ($matches) {
foreach ($matches[1] as $val) {
if (strpos($val, $domain) === false) {
$log_content = str_replace('href="' . $val . '"', 'href="' . $val . '" rel="external nofollow" ', $log_content);
}
}
}
preg_match_all('/src="(.*?)"/', $log_content, $matches);
if ($matches) {
foreach ($matches[1] as $val) {
if (strpos($val, $domain) === false) {
$log_content = str_replace('src="' . $val . '"', 'src="' . $val . '" rel="external nofollow" ', $log_content);
}
}
}
return $log_content;
}?>
|
在当前使用主题的echo_log.php、page.php里替换<?php echo $log_content; ?>
为 <?php echo content_nofollow($log_content,BLOG_URL);?>