把下面的代码插入到 functions.php 文件里面,记得要插入到之间 ,否则会出现错误:
//连接数量 $match_num_from = 1; //一个关键字少于多少不替换 $match_num_to = 10; //一个关键字最多替换 //连接到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 = "
这代码是直接从插件里面提取出来可能还会有多余的代码 ,目前测试没有bug,此外经过测试,个人建议最好将代码中的$match_num_to设为1,这样感觉体验最好,否则满屏的tags加链接感觉挺眼花缭乱的,改为1之后清爽不少,简单干净,这是我的追求~~