- 资源介绍
- 更新记录
- 安装教程
今天给大家分享一个WordPress SEO优化小技巧,该技巧能够实现文章内的关键词标签自动添加内链。
内链的好外,自然就不用说了,它可以让百度蜘蛛在你的网站爬行更多的地方。
当然,很多WordPress插件也可以实现这个功能,但是今天大资源网给大家分享的是不用插件给文章关键词标签自动添加内链的方法。
那怎么如何让WordPress站点的文章关键词标签自动添加内链呢?其实我们只需要在主题目录下的functions.php文件中添加一段代码就可以实现了。
<code title=””.str_replace(‘%s’,addcslashes($cleankeyword, ‘$’),__(‘【查看更多[%s]标签的文章】’)).”””;
$url .= ‘ target=”_blank”‘;
$url .= “>”.addcslashes($cleankeyword, ‘$’).”</a>”;
$limit = rand($match_num_from,$match_num_to);
$content = preg_replace( ‘|(<a[^>]+>)(.*)(‘.$ex_word.’)(.*)(</a[^>]*>)|U’.$case, ‘$1$2%&&&&&%$4$5’, $content);
$content = preg_replace( ‘|(<img)(.*?)(‘.$ex_word.’)(.*?)(>)|U’.$case, ‘$1$2%&&&&&%$4$5′, $content);
$cleankeyword = preg_quote($cleankeyword,”’);
$regEx = ”(?!((<.*?)|(<a.*?)))(‘. $cleankeyword . ‘)(?!(([^<>]*?)>)|([^>]*?</a>))’s’ . $case;
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( ‘%&&&&&%’, stripslashes($ex_word), $content);
}
}
return $content;
}
add_filter(‘the_content’,’tag_link’,1);//WordPress 文章关键词自动内链
function tag_sort($a, $b){
if ( $a->name == $b->name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
function tag_link($content){
$match_num_from = 1; //一个标签少于几次不链接
$match_num_to = 1; //一个标签最多链接几次
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, “tag_sort”);
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
//链接代码
$cleankeyword = stripslashes($keyword);
$url = “<a href=\”$link\” title=\””.str_replace(‘%s’,addcslashes($cleankeyword, ‘$’),__(‘更多关于 %s 的文章’)).”\””;
$url .= ‘ target=”_blank”‘;
$url .= “>”.addcslashes($cleankeyword, ‘$’).”</a>”;
$limit = rand($match_num_from,$match_num_to);
//不链接代码
$content = preg_replace( ‘|(<a[^>]+>)(.*)<pre.*?>(‘.$ex_word.’)(.*)<\/pre>(</a[^>]*>)|U’.$case, ‘$1$2%&&&&&%$4$5’, $content);
$content = preg_replace( ‘|(<img)(.*?)(‘.$ex_word.’)(.*?)(>)|U’.$case, ‘$1$2%&&&&&%$4$5’, $content);
$cleankeyword = preg_quote($cleankeyword,’\”);
$regEx = ‘\'(?!((<.*?)|(<a.*?)))(‘. $cleankeyword . ‘)(?!(([^<>]*?)>)|([^>]*?</a>))\’s’ . $case;
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( ‘%&&&&&%’, stripslashes($ex_word), $content);
}
}
return $content;
}
add_filter(‘the_content’,’tag_link’,1);
文章来自大资源网https://www.2426252023.com.cn转载请保留本链接,谢谢!
猜你喜欢
-
ripro子主题jizhi_chlid极致主题如何修改顶部最新公告?
2020-07-02 -
ripro添加自动随机文章阅读次数
2020-07-15 -
WordPress搜索结果排除指定页面/文章/自定义分类
2020-06-08 -
ripro如何添加css显示图?
2020-07-02 -
WordPress根据分类别名或ID选择内容页模板
2020-06-08 -
WordPress如何在父分类获取所有子分类/二级分类
2020-06-08 -
WordPress如何添加多个自定义菜单
2020-06-08 -
WordPress博客如何获取站点总访问量
2020-06-08 -
WordPress获取自定义文章类型分类法的所有文章循环
2020-06-08 -
WordPress如何在后台显示自带友情链接?
2020-06-08
-
ripro如何安装正版扩展?
2020-07-02 -
用代码完美实现wordpress蜘蛛爬行记录生成,远离插件,热爱速度!
2020-06-08 -
WordPress实现前台登录功能
2020-06-08 -
WordPress SEO优化 如何自动为文章添加标签链接增加站点内链
2020-11-21 -
wordpress登录界面样式优化
2020-06-08 -
WordPress如何给关键词和描述的结尾加上斜杠/
2020-07-05 -
WordPress如何调用指定分类文章
2020-06-08 -
WordPress让后台用户列表可以根据文章数进行排序
2020-06-08 -
WordPress教程:在后台文章列表添加作者筛选选项
2020-06-08 -
Blues主题1.7版本发布及更新内容说明
2020-06-08
猜你在找
常见问题FAQ
- 免费下载或者VIP会员专享资源能否直接商用?
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
- 提示下载完但解压或打开不了?
- 找不到素材资源介绍文章里的示例图片?
- 大资源
- 2020-06-08Hi,初次和大家见面了,请多关照!
最后编辑:2020-10-20

