Open
Reported for: WPML SEO 2.1.0
Overview of the issue
When using Different domains per language for your URL format, the sitemap doesn’t display the categories or product categories per language. Instead, it displays content from all your languages.
Workaround
Make a full backup of your site before proceeding:
- Add the following code to the theme’s functions.php file:
/* * WPML Workaround for compsupp-6571 */ add_filter('rank_math/sitemap/entry', 'wpml_compsupp6571_remove_sitemap_entry_from_different_domain', 10, 3); function wpml_compsupp6571_remove_sitemap_entry_from_different_domain ( $url, $type, $object ) { if (! class_exists('SitePress') || apply_filters( 'wpml_setting', false, 'language_negotiation_type' ) != 2 ) { return $url; } $current_language = apply_filters( 'wpml_current_language', NULL ); if ($type == 'post') { $post_language_details = apply_filters( 'wpml_post_language_details', NULL, $object->ID ) ; if ( isset($post_language_details['language_code']) && $post_language_details['language_code'] != $current_language) { return false; } } elseif ($type == 'term') { $args = array('element_id' => $object->term_taxonomy_id, 'element_type' => $object->taxonomy ); $term_language_details = apply_filters( 'wpml_element_language_details', NULL, $args ) ; if (isset($term_language_details->language_code) && $term_language_details->language_code != $current_language) { return false; } } return $url; }
- Go to Rank Math → Sitemap settings.
- Modify the Links Per Sitemap option and save the changes.
- Go to Settings → Permalinks and save. This will regenerate your permalinks.
- Check the sitemap. Each domain should display only content related to the current language.
Thanks. Seems to work great!
We are glad to know it worked, Sebastiaan!
Regards
Hello,
There’s still an issue with the wrong domain showing. Please see my latest response in this ticket:
https://wpml.org/forums/topic/rankmath-sitemap-is-showing-all-domains/#post-12915309
Thank you for sharing. Andreas will continue investigating this new situation.
Regards