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

Cập nhật lần cuối 30/08/2023 by trong WordPress vào 30/08/2023 có 118 Views

Bài toán như sau:

Ví dụ có link gốc:
Chuyên mục cha: your-domain.com/category/tin-tuc/tin-noi-bo/
Chuyên mục con: your-domain.com/category/tin-tuc/tin-noi-bo/
Chuyển thành:
Chuyên mục cha: your-domain.com/category/tin-tuc/tin-noi-bo/
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é

<?php
/*
Author: levantoan.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;
}

Từ khoá: remove slug parent category in wordpress

5/5 - (1 vote)
  • Bình luận
Sản phẩm nổi bật của Toản
x