wordpress tags标签改造id显示加后缀html显示-1

wordpress tags标签改造id显示加后缀html显示,对seo来说是特别友好的。

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

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

发表回复