wordpress官网入口 (WordPress-纯代码成功文章智能生成标签和标签参与内链)

文章编号:841 更新时间:2023-12-28 分类:互联网资讯 阅读次数:

资讯内容

纯代码成功WordPress文章智能生成标签,标签智能参与内链,比插件WPKeywordLink和AdInserter好用多了,每次写文章时都是自己整顿的标签并手动参与,哪怕是曾经存在的标签。关于已存在的标签最好是能够智能参与标签了,不然全手动的话易搜特必需会解体的,除此之内在网上发现许多的WordPress网站参与了标签云配置后,在文章中关于Tag标签的文字还参与了超链接,相当于给网站页面参与了内链配置,这关于网站提升,用户体验是很友好的。这个方法收费成功WordPress站点智能为文章参与Tag标签,并智能为这些标签参与链接变成内衔接的方法。

1、文章智能参与标签配置的成功 wordpress官网入口WordPres

只有将上方的代码参与进WordPress主题的functions.php中就能够成功了。

/*智能为文章参与标签*/add_action('save_post','auto_add_tags');functionauto_add_tags(){$tags=get_tags(array('hide_empty'=>false));$post_id=get_the_ID();$post_content=get_post($post_id)->post_content;if($tags){foreach($tagsas$tag){//假设文章内容产生了已经常使用过的标签,智能参与这些标签if(strpos($post_content,$tag->name)!==false)wp_set_post_tags($post_id,$tag->name,true);}}}

2、文章智能给文章内产生的标签内容参与超链接。

/*智能为文章内的标签参与内链*/$match_num_from=1;//一篇文章中同一个标签少于几次不智能链接$match_num_to=1;//一篇文章中同一个标签最多智能链接几次functiontag_sort($a,$b){if($a->name==$b->name)return0;return(strlen($a->name)>strlen($b->name))?-1:1;}functiontag_link($content){global$match_num_from,$match_num_to;$posttags=get_the_tags();if($posttags){usort($posttags,"tag_sort");foreach($posttagsas$tag){$link=get_tag_link($tag->term_id);$keyword=$tag->name;$cleankeyword=stripslashes($keyword);$url="".addcslashes($cleankeyword,'$')."";$limit=rand($match_num_from,$match_num_to);$content=preg_replace('|(]+>)(.*)('.$ex_word.')(.*)(]*>)|U'.$case,'$1$2%&&&&&%$4$5',$content);$content=preg_replace('|()|U'.$case,'$1$2%&&&&&%$4$5',$content);$cleankeyword=preg_quote($cleankeyword,'\'');$regEx='\'(?!((<.*?)|(]*?)>)|([^>]*?))\'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纯代码成功文章智能生成标签和标签参与内链

本文地址: https://yihaiquanyi.com/article/eef876249eddb3a92e6b.html

上一篇:macos软件推荐macOS软件下载Windows软件下...
下一篇:情感支援局在哪里看情感支招网...

发表评论