#
网站源码 2023年3月4日

WordPress代码替代插件实现关键字内链 提高站内权重

By 壹资源网 5 MIN READ

u6258947933908823861fm253fmtautoapp138fJPEG如果我们站长有比较重视网站SEO优化效果的,应该知道站内内链的重要性,我们可能在撰写文章的时候会手动添加当前网站中的内链至其他文章页面或者特定的关键字。有没有更好的办法自动化实现部分的特有关键字内链效果呢?当然是有的,在这篇文章中我们可以使用无插件实现文章Tag关键字实现内链效果。

也就是说,如果我们使用这个功能之后,我们只需要在当前文章中添加标签/关键字/Tag,就可以自动检索当前文章中出现的关键字实现内链。

/* 自动Tag标签关键字内链 壹资源网:www.iezyw.com*/
$match_num_from = 1; // 同一个标签少于几次不自动链接
$match_num_to = 4; // 一个关键字最多内链几次
function tag_sort($a, $b){
if ( $a->name == $b->name ) return 0;
return ( strlen($a->name) > strlen($b->name) ) ? -1 : 1;
}
function tin_tag_link($content){
global $match_num_from,$match_num_to;
$posttags = get_the_tags();
if ($posttags) {
usort($posttags, "tag_sort");
$ex_word = '';
$case = '';
foreach($posttags as $tag) {
$link = get_tag_link($tag->term_id);
$keyword = $tag->name;
$cleankeyword = stripslashes($keyword);
$url = "<a href=\"$link\" class=\"tooltip-trigger tin\" 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','tin_tag_link',12);

将当前脚本添加到当前主题的Functions.php文件中。我们可以根据实际设置match_num_from、match_num_to,或者我们就默认即可。



免责声明

站点信息:本站网址:https://www.iezyw.com | 资源解压密码:@iezyw.com

性质说明:资源源于网络收集,本站收取的费用仅为收集与整理的人工成本,并非资源本身之售价。

版权声明:内容仅供学习参考,如有侵权请联系邮箱 admin@iezyw.com,我们将及时处理。

免责条款:资源不代表本站立场,本站不对其观点及真实性负责,请用户自行甄别。

合规声明:严禁以任何方式发布或转载违法规信息,访客发现请向站长举报。

资源维护:资源多为云盘存储,如遇链接失效,请发邮件给到我们,我们会及时更新。

😢 检测到广告拦截

您好,我们检测到您使用了广告拦截插件。

本站坚持分享优质资源,广告收入是我们持续更新的唯一动力。

恳请将本站加入白名单,支持我们继续"用爱发电"!