wordpress文章内容中出现标签词自动加站内链接
为何让wordpress文章内容中出现标签词自动加站内链接呢?
1,提高用户体验,可以更详细的了解相关关键词的文章
2,提高站内链接
3,提高爬虫爬取
好处这么多直接上方法吧:在主题的functions.php文件的后面添加下列语句
// 文章添加关键词链接
function auto_post_link($content) {
global $post;
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$content = preg_replace(‘\'(?!((<.*?)|(<a.*?)))(‘. $keyword . ‘)(?!(([^<>]*?)>)|([^>]*?))\’s’,”.$keyword.”,$content,1);//最多替换2个重复的词,避免过度SEO
}
}
return $content;
}
add_filter (‘the_content’, ‘auto_post_link’,0);
原创文章,转载时必须以链接形式注明本文来自云中客,本文固定链接:http://vr.ccyzk.com/394.htm