很多 SEO 朋友应该知道文章内链的重要性。内部链接结构可以引导权重的传递,提高收藏,提高内部页面的排名。
如何将内链自动添加到 wordpress 博客的文章关键字标签中?实际上,我们只需要向主题目录中的functions.php文件添加一段代码。
//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" rel="external nofollow" title="".str_replace('{5cc1b29162d549a8071384de182cc9fc6e6a0fd85e7907f22fd9e18cff4269c3}s',addcslashes($cleankeyword, '$'),__('更多关于 {5cc1b29162d549a8071384de182cc9fc6e6a0fd85e7907f22fd9e18cff4269c3}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{5cc1b29162d549a8071384de182cc9fc6e6a0fd85e7907f22fd9e18cff4269c3}&&&&&{5cc1b29162d549a8071384de182cc9fc6e6a0fd85e7907f22fd9e18cff4269c3}$4$5', $content);
$content = preg_replace( '|(<img)(.*?)('.$ex_word.')(.*?)(>)|U'.$case, '$1$2{5cc1b29162d549a8071384de182cc9fc6e6a0fd85e7907f22fd9e18cff4269c3}&&&&&{5cc1b29162d549a8071384de182cc9fc6e6a0fd85e7907f22fd9e18cff4269c3}$4$5', $content);
$cleankeyword = preg_quote($cleankeyword,'\'');
$regEx = '\'(?!((<.*?)|(<a.*?)))('. $cleankeyword . ')(?!(([^<>]*?)>)|([^>]*?</a>))\'s' . $case;
$content = preg_replace($regEx,$url,$content,$limit);
$content = str_replace( '{5cc1b29162d549a8071384de182cc9fc6e6a0fd85e7907f22fd9e18cff4269c3}&&&&&{5cc1b29162d549a8071384de182cc9fc6e6a0fd85e7907f22fd9e18cff4269c3}', stripslashes($ex_word), $content);
}
}
return $content;
}
add_filter('the_content','tag_link',1);
转载请注明:汇站网 » 自动将内链添加到 WordPress 优化的文章标签中
汇站
站长资源下载中心-找源码上汇站
常见问题
- 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
相关文章
猜你喜欢
- 7B2 PRO主题5.4.2免授权版本(直接安装) 2024-05-11
- 如果WordPress搜索结果为空,自动跳转到网站首页 2024-02-01
- 浏览器缓存可以分为强缓存和协商缓存两种方式 2024-01-21
- 如何让WordPress支持上传WebP格式图片? 2024-01-20
- 利用WordPress设置API实现自定义设置页面。 2024-01-20
- WordPress api接口 版本历史 2024-01-20
- WordPress用户密码加密和验证的详细解释 2024-01-19
- WordPress禁用媒体附件页面教程 2024-01-19
- WordPress修改了文章的默认密码保护提示 2024-01-19
- WordPress配置(站群)多站点详细教程方法 2024-01-19