当前位置:首页 >正文

wordpress关键字tag内链的实现方法

百度: 已收录 | 最后修改时间: 2023-01-02 5:32:12,
pos机流量卡
pos机流量卡

wordpress关键字tag内链的实现方法如今已经不是外链为王的时代,已经是用户体验最为重要的事情,那么我们一篇文章适当的利用内链可以给用户很好的用户体验,比如扩展阅读可以让用户知道更多关于本网站关于此内容更多,让用户更有粘性,随着uv是肯定不断的上升,所以内链的作用是很有必要的

那么wordpress如何实现内链,今天给大家讲的是tag关键字实现的方法

下面是实现的代码:代码来至:张戈博客

//连接数量
$match_num_from = 1; //一个关键字少于多少不替换
$match_num_to = 2; //一个关键字最多替换
//连接到wordpress的模块
add_filter(‘the_content’,’tag_link’,1);
//按长度排序
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){
global $match_num_from,$match_num_to;
$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, ‘$’),__(‘view all posts in %s’)).”””;
$url .= ‘ target=”_blank” class=”tag_link”‘;
$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;

把以上的代码复制到functions.php文件当中,在<?php和之间?>就可以了,然后保存上传就解决了。

还有很多朋友就说我已经上传了,为什么没有出现内链啦,当然是tag肯定就是需要你在标签的时候添加相同的标签然后再可以实现彼此的内链链接。比如你是 wp置顶这下面tag关键字链接那么你就需要在你想要内链的上面都添加tag关键字这个标签才能实现。

对于wordpress关键字tag内链的实现方法解答就到这里了,大家在使用pos机刷卡、pos机办理、pos机使用等等问题,上面有不明白的都可以加我微信(chengzhi369),使用pos机一定要在正规渠道办理,这样子使用才会更加的安全可靠,有保障。

版权声明:本文由作者:卡卡哥 原创,不允许转载,否则必追究法律责任,谢谢配合!!本文链接:https://www.chinahzx.cn/1185.html


pos机免费办理-微信:170-025-66688