什么是 nofollow
?
nofollow
是标记的属性值。
nofollow
的作用是什么?
nofollow
是告诉搜索引擎不要在此页面上跟踪链接或不跟踪此链接,也不会导出此链接。
Nofollow
对WordPress
优化具有一定的重要性。如果文章中存在外部链条地址,则必须添加 nofollw
。
nofollow
案例
1 |
使用方法
将以下代码添加到主题functions
.php
文件
//给文章外链添加 nofollow
add_filter
('the_content
','web589_the_content_nofollow
',999);
function
web589_the_content_nofollow
($content
){
preg_match_all
('/href
="(.*?)" rel
="external
nofollow
" /',$content
,$matches
);
if
($matches
){
foreach
($matches
[1] as
$val
){
if
( strpos
($val
,home_url
())===false
) $content
=str_replace
("href
="$val
"", "href
="$val
" rel
="nofollow
" ",$content
);
}
}
return
$content
;
}
转载请注明:汇站网 » WordPress如何在文章的外链中添加nofollow