Skip Navigation

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 -
- 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 14 replies, has 2 voices.

Last updated by Long Nguyen 1 year, 3 months ago.

Assisted by: Long Nguyen.

Author Posts
August 7, 2023 at 7:23 am #14161521

Long Nguyen
Supporter

Languages: English (English )

Timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Hi,

I got some information from our 2nd tier support, please check the workaround below to fix the issue.

❌ IMPORTANT: Please backup your database and website before proceeding ❌

1. Edit the file wp-content\plugins\all-in-one-seo-pack\app\Common\Sitemap\Localization.php, find the code around line 71:

if ( (int) $entryId === (int) $translation->element_id ) {
	$entry['language'] = $translation->language_code;
	continue;
}

and replace it with:

if ( (int) $entryId === (int) $translation->element_id ) {
	//$entry['language'] = $translation->language_code;
	// WPML workaround for compsupp-6899
	$wpml_languages = apply_filters( 'wpml_active_languages', NULL, 'orderby=id&order=desc' ); 				
	$entry['language'] = $wpml_languages[$translation->language_code]['tag'];
	continue;
}

find the code around line 94:

$currentLanguage = ! empty( self::$wpml['activeLanguages'][ $translation->language_code ] ) ? self::$wpml['activeLanguages'][ $translation->language_code ] : null;
$languageCode    = ! empty( $currentLanguage['tag'] ) ? $currentLanguage['tag'] : $translation->language_code;

replace it with:

$currentLanguage = ! empty( self::$wpml['activeLanguages'][ $translation->language_code ] ) ? self::$wpml['activeLanguages'][ $translation->language_code ] : null;
$languageCode    = ! empty( $currentLanguage['tag'] ) ? $currentLanguage['tag'] : $translation->language_code;

// WPML workaround for compsupp-6899
$wpml_languages = apply_filters( 'wpml_active_languages', NULL, 'orderby=id&order=desc' ); 				
$languageCode= $wpml_languages[$translation->language_code]['tag'];

2. Edit the file wp-content\plugins\all-in-one-seo-pack\app\Common\Sitemap\Content.php, find the code around line 404

foreach ( $translatedHomepages as $languageCode => $translatedHomepage ) {
	if ( untrailingslashit( $translatedHomepage['url'] ) !== untrailingslashit( $homepageEntry['loc'] ) ) {		
		$homepageEntry['languages'][] = [
			'language' => $languageCode,
			'location' => $translatedHomepage['url']
		];
	}
}

replace it with:

foreach ( $translatedHomepages as $languageCode => $translatedHomepage ) {
	if ( untrailingslashit( $translatedHomepage['url'] ) !== untrailingslashit( $homepageEntry['loc'] ) ) {
		// WPML workaround for compsupp-6899
		$wpml_languages = apply_filters( 'wpml_active_languages', NULL, 'orderby=id&order=desc' ); 				
		$languageCode = $wpml_languages[$languageCode]['tag'];
		
		$homepageEntry['languages'][] = [
			'language' => $languageCode,
			'location' => $translatedHomepage['url']
		];
	}
}

3. Also, if you want to remove duplicate posts on the sitemap page, please edit the file wp-content\plugins\all-in-one-seo-pack\app\Common\Sitemap\Localization.php, around line 54

if ( empty( $translations ) ) {
	return $entry;
}

replace it with:

if ( empty( $translations ) ) {
	return $entry;
}

//WPML Workaround for compsupp-6899
if (class_exists('Sitepress')){
	$wpml_default_lang = apply_filters('wpml_default_language', NULL );
	
	$type = apply_filters( 'wpml_element_type', get_post_type( $entryId ) );
	$args = array('element_id' => $entryId, 'element_type' => $type );
	$entry_language_code = apply_filters( 'wpml_element_language_code', null, $args );
	
	if ( $wpml_default_lang != $entry_language_code) {
		return $entry;
	}
}

Look forward to your reply.
Thanks

The topic ‘[Closed] [AIO SEO] Sitemap display duplicate links’ is closed to new replies.