Loại bỏ slug category cha khỏi đường dẫn category trong WordPress - WordPress Developer

Loại bỏ slug category cha khỏi đường dẫn category trong WordPress

Yêu cầu như sau:

Link gốc:

  • Chuyên mục cha: your-domain.com/category/tin-tuc/
  • Chuyên mục con: your-domain.com/category/tin-tuc/tin-noi-bo/

Cần chuyển thành:

  • Chuyên mục cha: your-domain.com/category/tin-tuc/
  • Chuyên mục con: your-domain.com/category/tin-noi-bo/

Bạn chỉ cần thêm đoạn code sau vào functions.php của theme đang kích hoạt rồi vào Cài đặt > đường dẫn tĩnh > ấn Save change là xong nhé

/*
Author: LayoutUp.com
Insert this code to functions.php, then update permalink Setting -> Permalink
*/
add_filter('register_taxonomy_args','devvn_remove_parent_slug_category', 10, 2);
function devvn_remove_parent_slug_category($args, $name){
    if($name == 'category'){
        $args['rewrite']['hierarchical'] = false;
    }
    return $args;
}