WPML
Status
Resolved
Type
Bug
Reported for
WPML SEO 2.1.0
Resolved in
2.2.0
Related plugin/theme
Rank Math SEO
Topic tags
Compatibility

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:


  1. 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;
    }


  2. Go to Rank MathSitemap settings.

  3. Modify the Links Per Sitemap option and save the changes.

  4. Go to SettingsPermalinks and save. This will regenerate your permalinks.

  5. Check the sitemap. Each domain should display only content related to the current language.

All known issues →