• Share Tốt – Chia Sẻ Kinh Nghiệm Tồi Tệ
Share Tốt
Liên hệ quảng cáo 0965 21 8696
  • Trang chủ
  • WordPress
  • Share Code
  • Dịch vụ Web
  • 365 Ngày 24/7
  • Thủ Thuật
  • Lập Trình PHP
  • News CNTT
  • SEO Google
No Result
View All Result
  • Trang chủ
  • WordPress
  • Share Code
  • Dịch vụ Web
  • 365 Ngày 24/7
  • Thủ Thuật
  • Lập Trình PHP
  • News CNTT
  • SEO Google
No Result
View All Result
Share Tốt
No Result
View All Result

Trang chủ Wordpress

Code xóa /category/ url danh mục WordPress

0
SHARES
36
VIEWS
Share on FacebookShare on Twitter

Cách để xóa đường dẫn danh mục hay chuyên mục có chữ /category/ trên đường dẫn website sử dụng wordpress, các bạn chỉ cần làm như sau ? Nếu trường hợp code trên không hoạt động thì có thể do WordPress đang cache đang cache cấu trúc đường dẫn, chúng ta cần vào [ Settings ( Cài đặt ) ] => [ Permalinks ( Đường dẫn tĩnh ) ] => bấm [ Save changes ] để cập nhật lại cấu trúc đường dẫn.

Xóa bỏ /category/ trong WordPress

Thêm đoạn code sau vào file functions.php


/* actions */
add_action( 'created_category', 'remove_category_url_refresh_rules' );
add_action( 'delete_category', 'remove_category_url_refresh_rules' );
add_action( 'edited_category', 'remove_category_url_refresh_rules' );
add_action( 'init', 'remove_category_url_permastruct' );

/* filters */
add_filter( 'category_rewrite_rules', 'remove_category_url_rewrite_rules' );
add_filter( 'query_vars', 'remove_category_url_query_vars' ); // Adds 'category_redirect' query variable
add_filter( 'request', 'remove_category_url_request' ); // Redirects if 'category_redirect' is set

function remove_category_url_refresh_rules() {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}

function remove_category_url_deactivate() {
remove_filter( 'category_rewrite_rules',
'remove_category_url_rewrite_rules' ); // We don't want to insert our custom rules again
remove_category_url_refresh_rules();
}

/**
* Removes category base.
*
* @return void
*/
function remove_category_url_permastruct() {
global $wp_rewrite, $wp_version;

if ( 3.4 <= $wp_version ) {
$wp_rewrite->extra_permastructs['category']['struct'] = '%category%';
} else {
$wp_rewrite->extra_permastructs['category'][0] = '%category%';
}
}

/**
* Adds our custom category rewrite rules.
*
* @param array $category_rewrite Category rewrite rules.
*
* @return array
*/
function remove_category_url_rewrite_rules( $category_rewrite ) {
global $wp_rewrite;

$category_rewrite = array();

/* WPML is present: temporary disable terms_clauses filter to get all categories for rewrite */
if ( class_exists( 'Sitepress' ) ) {
global $sitepress;

remove_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
$categories = get_categories( array( 'hide_empty' => false, '_icl_show_all_langs' => true ) );
add_filter( 'terms_clauses', array( $sitepress, 'terms_clauses' ) );
} else {
$categories = get_categories( array( 'hide_empty' => false ) );
}

foreach ( $categories as $category ) {
$category_nicename = $category->slug;
if ( $category->parent == $category->cat_ID ) {
$category->parent = 0;
} elseif ( 0 != $category->parent ) {
$category_nicename = get_category_parents( $category->parent, false, '/', true ) . $category_nicename;
}
$category_rewrite[ '(' . $category_nicename . ')/(?:feed/)?(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$category_rewrite[ '(' . $category_nicename . ')/page/?([0-9]{1,})/?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[2]';
$category_rewrite[ '(' . $category_nicename . ')/?$' ] = 'index.php?category_name=$matches[1]';
}

// Redirect support from Old Category Base
$old_category_base = get_option( 'category_base' ) ? get_option( 'category_base' ) : 'category';
$old_category_base = trim( $old_category_base, '/' );
$category_rewrite[ $old_category_base . '/(.*)$' ] = 'index.php?category_redirect=$matches[1]';

return $category_rewrite;
}

function remove_category_url_query_vars( $public_query_vars ) {
$public_query_vars[] = 'category_redirect';

return $public_query_vars;
}

/**
* Handles category redirects.
*
* @param $query_vars Current query vars.
*
* @return array $query_vars, or void if category_redirect is present.
*/
function remove_category_url_request( $query_vars ) {
if ( isset( $query_vars['category_redirect'] ) ) {
$catlink = trailingslashit( get_option( 'home' ) ) . user_trailingslashit( $query_vars['category_redirect'],
'category' );
status_header( 301 );
header( "Location: $catlink" );
exit;
}

return $query_vars;
}

 

Đám mây từ khóa

365 Ngày 24/7 Design Dịch vụ Web Lập Trình PHP News CNTT SEO Google Share Code Thủ Thuật Wordpress
ADVERTISEMENT

Tin tức gần đây

TOP 05 Tiệm cắt tóc ( Salon ) tốt nhất Hải Phòng

TOP 05 Tiệm cắt tóc ( Salon ) tốt nhất Hải Phòng

28 Tháng Hai, 2021
Top 5 công ty thiết kế website chuyên nghiệp uy tín TPHCM

#TOP Công ty dịch vụ thiết kế APP uy tín ở tại Hải Phòng

30 Tháng Mười, 2020
Gắn nút Hotline – Zalo – Facebook cho Website năm 2020

Gắn nút Hotline – Zalo – Facebook cho Website năm 2020

14 Tháng Mười Một, 2020
Lỗi đầy nội dung cơ sở dữ liệu MySql ” fatal error: allowed memory size of “

Lỗi đầy nội dung cơ sở dữ liệu MySql ” fatal error: allowed memory size of “

15 Tháng Mười, 2020

Bài viết liên quan

Gắn nút Hotline – Zalo – Facebook cho Website năm 2020
Share Code

Gắn nút Hotline – Zalo – Facebook cho Website năm 2020

14 Tháng Mười Một, 2020
Lỗi đầy nội dung cơ sở dữ liệu MySql ” fatal error: allowed memory size of “
Wordpress

Lỗi đầy nội dung cơ sở dữ liệu MySql ” fatal error: allowed memory size of “

15 Tháng Mười, 2020
Cách code đưa nút Add Media WordPress Custom
Share Code

Cách code đưa nút Add Media WordPress Custom

27 Tháng Bảy, 2020
Code thêm tab cạnh mô tả cho woocommerce
Wordpress

Code thêm tab cạnh mô tả cho woocommerce

20 Tháng Năm, 2020
Loại bỏ trong đường dẫn danh mục sản phẩm Woocommerce
Wordpress

Thay đổi thẻ html woocommerce change product title p to h3

12 Tháng Sáu, 2020

Bài tiếp theo
Functions thay đổi chữ “select options” woocommerce WordPress

Functions thay đổi chữ "select options" woocommerce Wordpress

Share Tốt

Share Tốt chia sẻ kinh nghiệm, tin tức, thủ thuật, bài giảng hay cho mọi lứa tuổi xem trên trang.

Theo dõi tôi

Chuyên Mục

  • 365 Ngày 24/7
  • Design
  • Dịch vụ Web
  • Lập Trình PHP
  • News CNTT
  • SEO Google
  • Share Code
  • Thủ Thuật
  • Wordpress

Bài viết mới

TOP 05 Tiệm cắt tóc ( Salon ) tốt nhất Hải Phòng

TOP 05 Tiệm cắt tóc ( Salon ) tốt nhất Hải Phòng

28 Tháng Hai, 2021
Top 5 công ty thiết kế website chuyên nghiệp uy tín TPHCM

#TOP Công ty dịch vụ thiết kế APP uy tín ở tại Hải Phòng

30 Tháng Mười, 2020
  • Share Tốt – Chia Sẻ Kinh Nghiệm Tồi Tệ

© 2020 Share Tốt - Thiết kế web Hải Phòng.

No Result
View All Result
  • Trang chủ
  • WordPress
  • Share Code
  • Dịch vụ Web
  • 365 Ngày 24/7
  • Thủ Thuật
  • Lập Trình PHP
  • News CNTT
  • SEO Google

© 2020 Share Tốt - Thiết kế web Hải Phòng.