Hướng Dẫn Bỏ Slug Portfolio Feature_item Và Feature_item_category
Nhiều anh em sài Fortfolio thường sẽ dính URL mặc định của Portfolio là Feature_item Và Feature_item_category, nhất là anh em đang sử dụng Theme Flatsome hay có cái này, nên hôm nay qua bài Hướng Dẫn Bỏ Slug Portfolio này mong sẽ giúp các bạn cách xoá URL này đi cho chuẩn SEO luôn nhé !
Cách làm cũng khá đơn giản, như mọi khi các bạn coppy đoạn code bên dưới bỏ vào function.php của theme nha. thường thì sẽ theo đường dẫn sau “sửa giao diện -> theme của bạn -> function.php”
-
Đoạn code bỏ Feature_item trong Slug Portfolio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersfunction ah_remove_custom_post_type_slug( $post_link, $post, $leavename ) { if ( ! in_array( $post->post_type, array( 'featured_item' ) ) || 'publish' != $post->post_status ) // url featured_item return $post_link; $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); return $post_link; } add_filter( 'post_type_link', 'ah_remove_custom_post_type_slug', 10, 3 ); function ah_parse_request_tricksy( $query ) { if ( ! $query->is_main_query() ) return; if ( 2 != count( $query->query ) || ! isset( $query->query['page'] ) ) return; if ( ! empty( $query->query['name'] ) ) $query->set( 'post_type', array( 'post', 'featured_item', 'page' ) ); } add_action( 'pre_get_posts', 'ah_parse_request_tricksy' );
Ghi chú: để ý dòng số 2 có featured_item là url muốn xoá, bạn để ý thử Portfolio của bạn đang sử dụng và thay cho đung nhé, còn mặc định flatsome là như trên -
Đoạn code bỏ Feature_item_category trong slug danh mục Portfolio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersadd_filter('request', 'rudr_change_term_request', 1, 1 ); function rudr_change_term_request($query){ $tax_name = 'featured_item_category'; // specify you taxonomy name here, it can be also 'category' or 'post_tag' // Request for child terms differs, we should make an additional check if( $query['attachment'] ) : $include_children = true; $name = $query['attachment']; else: $include_children = false; $name = $query['name']; endif; $term = get_term_by('slug', $name, $tax_name); // get the current term to make sure it exists if (isset($name) && $term && !is_wp_error($term)): // check it here if( $include_children ) { unset($query['attachment']); $parent = $term->parent; while( $parent ) { $parent_term = get_term( $parent, $tax_name); $name = $parent_term->slug . '/' . $name; $parent = $parent_term->parent; } } else { unset($query['name']); } switch( $tax_name ): case 'category':{ $query['category_name'] = $name; // for categories break; } case 'post_tag':{ $query['tag'] = $name; // for post tags break; } default:{ $query[$tax_name] = $name; // for another taxonomies break; } endswitch; endif; return $query; } add_filter( 'term_link', 'rudr_term_permalink', 10, 3 ); function rudr_term_permalink( $url, $term, $taxonomy ){ $taxonomy_name = 'featured_item_category'; // your taxonomy name here $taxonomy_slug = 'featured_item_category'; // the taxonomy slug can be different with the taxonomy name (like 'post_tag' and 'tag' ) // exit the function if taxonomy slug is not in URL if ( strpos($url, $taxonomy_slug) === FALSE || $taxonomy != $taxonomy_name ) return $url; $url = str_replace('/' . $taxonomy_slug, '', $url); return $url; }
Ghi Chú: đê ý dòng số 3 có featured_item_category là url muốn xoá, bạn để ý thử Portfolio của bạn đang sử dụng và thay cho đung nhé, còn mặc định flatsome là như trên -
Cập nhật lại đường dẫn
sau khi chèn code xóa Slug Portfolio thì bạn nên cập nhật lại đường dẫn tránh gây lỗi website, cái này tuỳ web nha, nhưng cập nhật cho chắc.
cách cập nhật là bạn làm theo đường dẫn sau:
Cài Đặt -> Đường Dẫn Tĩnh -> Cập Nhật
Hướng Dẫn Bỏ Slug Portfolio Feature_item Và Feature_item_category Vậy là xong, bạn có thể xem demo qua link này nhé: https://trungtamhsk.com/thanh-tich/ đang sử dụng Portfolio
Nếu bạn thấy hay hãy click quảng cáo ủng hộ giúp mình đc 1 gói mỳ tôm ăn qua ngày là được, thank you mọi người.
Các bạn có thắc mắc gì thì liên hệ mình nhé thông qua: website: congdongshop.com hoặc congdongblog.com , youngplus.vn của mình nhé,
Hotline: 0386270225 (A.Thông) nếu bạn có nhu cầu làm website.