wordpress二次开发tags改id显示

 2141

wordpress二次开发tags改id显示,后缀加html,伪静态格式对seo特别友好.


wordpress二次开发tags改id显示


使用文本编辑器打开当前主题目录下的 functions.php,添加以下 php 代码:

最终显示格式:id+html方式展示

  1. add_action('generate_rewrite_rules','tag_rewrite_rules');
  2. add_filter('term_link','tag_term_link',10,3);
  3. add_action('query_vars', 'tag_query_vars');
  4. function tag_rewrite_rules($wp_rewrite) {
  5.     $new_rules = array(
  6.             'tag/(\d+)/feed/(feed|rdf|rss|rss2|atom).html' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
  7.             'tag/(\d+)/(feed|rdf|rss|rss2|atom).html' => 'index.php?tag_id=$matches[1]&feed=$matches[2]',
  8.             'tag/(\d+)/embed.html' => 'index.php?tag_id=$matches[1]&embed=true',
  9.             'tag/(\d+)/page/(\d+).html' => 'index.php?tag_id=$matches[1]&paged=$matches[2]',
  10.             'tag/(\d+).html' => 'index.php?tag_id=$matches[1]',
  11.         );
  12.     $wp_rewrite->rules = $new_rules + $wp_rewrite->rules;
  13. }
  14. function tag_term_link($link,$term,$taxonomy) {
  15.     if($taxonomy=='post_tag') {
  16.         return home_url('/tag/'.$term->term_id.'.html');
  17.     }
  18.     return $link;
  19. }
  20. function tag_query_vars($public_query_vars) {
  21.     $public_query_vars[] = 'tag_id';
  22.     return $public_query_vars;
  23. }


本文网址:https://www.zztuku.com/index.php/detail-12947.html
站长图库 - wordpress二次开发tags改id显示
申明:如有侵犯,请 联系我们 删除。

评论(0)条

您还没有登录,请 登录 后发表评论!

提示:请勿发布广告垃圾评论,否则封号处理!!

    编辑推荐