发布文章,自动随机生成关键词标签,并关联到文章中,简单快捷

可提高网站seo转化,蜘蛛索引

复制下方代码,加到网站主题,

xxx.xxx.xxx/wp-content/themes/自己主题文件夹/footer.php.php【functions.php这个文件底部即可】文件底部保存即可

隐藏内容
本内容登录后免费查看

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);

 

 

声明:
服务说明:
(1)资源来源于网络公开发表文件,所有资料仅供学习交流;
(2)学分仅用来维持网站运营,性质为用户友情赞助,并非购买文件费用(1元=10学分);
(3)如遇百度网盘分享链接失效,可以在链接显示下方提交工单,管理员都会及时处理的或加微信处理;
(4)在您未收到文件之前,可以联系客服微信:yiguoxue78 进行退款;如果已经获取资料是无法退款请悉知!
(5)不用担心不给资料,如果没有及时回复也不用担心,看到了都会发给您的!放心!

温馨提示:部分玄学、武术、医学等资料非专业人士请勿模仿学习,仅供参考!
以上内容由网站用户发布,如有侵权,请联系我们立即删除!联系微信:yiguoxue78本站所有内容适用本站免责声明