WordPress mặc định có 2 dạng tạo và và lưu trữ nội dung chính là “Post” và “Page”. Ở dạng “Post” nếu muốn loại bỏ “category” có trong đường dẫn thì bạn chỉ cần tùy chỉnh permalink trong Setting của trình quản trị là xong, nhưng với dạng “Page” thì hơi gian nan chút. Bài viết sau đây ItVN Blog sẽ hướng dẫn bạn xóa parent page trong đường dẫn slug của wordpress nhé.
- Hướng dẫn tạo website bằng wordpress.com miễn phí mới nhất
- Tại sao nội dung trong wordpress có chứa thẻ rel=”noopener” hoặc rel =”noreferrer”
- Top 7 plugin tối ưu website wordpress miễn phí tốt nhất
- Hướng dẫn gắn plugin comment wordpress bằng facebook cho website
- 3 plugin nén ảnh wordpress tốt nhất hiện nay
Cách xóa parent page trong đường dẫn (slug)
Ví dụ bạn muốn biến site.com/parent-page/child-page thành site.com/child-page Bạn sẽ can thiệp vào function để remove “parent page” slug đi. Cách làm này khác với một số cách thông thường, chúng lạm dụng phương pháp redirect (301) để điều hướng url, điều này gây nhiều phiền toái về sau nếu bạn làm SEO hoặc chuyển giao diện…

Dễ dàng nhất là bạn copy đoạn này và thêm vào function.php của theme hoặc child-theme là xong:
function wpse_182006_pages_permalink( $link, $post_id) {
// get the post_type and evaluate
$posttype = get_post_field( 'post_type', $post_id, 'display' );
if ($posttype !== 'page'){
return link;
}
// build the uri from the slug
$slugname = get_post_field( 'post_name', $post_id, 'display' );
$slugname = $slugname."/";
$link = home_url($slugname);
return $link;
}
add_filter( 'page_link', 'wpse_182006_pages_permalink', 10, 3 );
Nguồn: chuotbu.com/cach-xoa-parent-page-trong-duong-dan-slug-cua-wordpress-permalink