- Trạng thái
- Đã giải quyết
- Được báo cáo cho
- WPML SEO 2.2.4
- Đã giải quyết trong
- WPML SEO 2.2.5
- Plugin/giao diện liên quan
- Rank Math SEO
- Thẻ chủ đề
- Compatibility
Tổng quan về lỗi
Khi sử dụng RankMath SEO với WPML, bạn có thể gặp phải lỗi trong đó các URL trang chủ trong mã nguồn của sitemap <xhtml:link rel="alternate" hreflang="..."> không chính xác đối với các ngôn ngữ phụ. Thay vì hiển thị trang chủ theo ngôn ngữ cụ thể (ví dụ: domain.com/?lang=es), sitemap lại xuất ra một URL trang đầy đủ (ví dụ: domain.com/page-slug/?lang=es).
Giải pháp tạm thời
Vui lòng đảm bảo bạn có bản sao lưu toàn bộ trang web trước khi tiến hành.
- Mở tệp …/wp-content/plugins/wp-seo-multilingual/classes/Shared/Sitemap/BaseAlternateLangHooks.php.
- Tìm dòng 88.
- Thay thế:
$mapPermalink = function ( $id, $language ) use ( $getPermalink ) { return apply_filters( 'wpml_permalink', $getPermalink( $id ), $language ); };
- Bằng:
$mapPermalink = function ( $id, $language ) use ( $getPermalink ) { // WPML Workaround for wpmlsupp-13368 $front_id = (int) get_option( 'page_on_front' ); if ( $front_id ) { $default_lang = apply_filters( 'wpml_default_language', null ); $id_in_default = (int) apply_filters( 'wpml_object_id', (int) $id, 'page', false, $default_lang ); if ( $id_in_default && $id_in_default === $front_id ) { return apply_filters( 'wpml_permalink', trailingslashit( home_url() ), $language ); } } return apply_filters( 'wpml_permalink', $getPermalink( $id ), $language ); };
- Tạo lại sitemap: Đi tới “Rank Math > Sitemap Settings”, thay đổi giá trị “Links per sitemap” và lưu.