最新消息:郑州SEO笔记与大家一起分享和学习seo知识,一起分析网站seo案例,探析seo技巧!

修改WordPress的文章TAG标签用ID显示

服务器 admin 701浏览

今天来分享一篇教程,修改WordPress的文章TAG标签用ID显示,wordpress默认的tag标签输出的url是以原字输出,也就是你的tag是中文,输出的url也是带有中文的!但是中文的显示有时候会被转码,这次的修改会让你的tag更简化!

下面放出代码:把代码放到主题根目录下的functions.php文件就行了

!!!改了之后记得进入后台,设置-固定链接-重新点保存才会生效!!要不然变成404了。

add_action('generate_rewrite_rules','tag_rewrite_rules');  
   
    add_filter('term_link','tag_term_link',10,3);  
   
    add_action('query_vars', 'tag_query_vars');  
   
    function tag_rewrite_rules($wp_rewrite){  
   
    $new_rules = array(  
   
    'tag/(\d+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',  
   
    'tag/(\d+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',  
   
    'tag/(\d+)/embed/?$' => 'index.php?tag_id=$matches[1]&embed=true',  
   
    'tag/(\d+)/page/(\d+)/?$' => 'index.php?tag_id=$matches[1]&paged=$matches[2]',  
   
    'tag/(\d+)/?$' => 'index.php?tag_id=$matches[1]',  
   
    );  
   
    $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;  
   
    }  
    function tag_term_link($link,$term,$taxonomy){  
   
    if($taxonomy=='post_tag'){  
   
    return home_url('/tag/'.$term->term_id);  
   
    }  
    return $link;  
    }  
    function tag_query_vars($public_query_vars){  
   
    $public_query_vars[] = 'tag_id';  
   
    return $public_query_vars;  
   
    }

转载请注明:郑州SEO优化_郑州网站优化 » 修改WordPress的文章TAG标签用ID显示