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.

This topic contains 12 replies, has 2 voices.

Last updated by Raja Mohammed 4 years, 2 months ago.

Assisted by: Raja Mohammed.

Author Posts
December 18, 2019 at 6:49 am #5152793

marketingV

Semrush is showing huge number of pages that have hreflang conflicts.

What can be the solution to solve this problem?

image (2).png
image (1).png
image.png
December 18, 2019 at 7:18 am #5152967

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hi,

Please leave me a message here once you have the results.

Kind regards
Raja

December 23, 2019 at 8:23 am #5182769

marketingV

After adding your this solution

/* ---------------------------------------------------------------------------
* Set hreflang="x-default" with WPML
* --------------------------------------------------------------------------- */
add_filter('wpml_alternate_hreflang', 'wps_head_hreflang_xdefault', 10, 2);
function wps_head_hreflang_xdefault($url, $lang_code) {

if($lang_code == apply_filters('wpml_default_language', NULL )) {

echo '<link rel="alternate" href="' . $url . '" hreflang="x-default" />'.PHP_EOL;
}

return $url;
}

The issue didn't solve yet. Instead of previous 192 issues, now getting 319 issues from SEMrush.

December 23, 2019 at 1:43 pm #5184741

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Please remove the previous code and try adding the code below in your theme functions.php file. This might work.

// add x-default to default language instead of default lang hreflang

add_filter( 'wpml_hreflangs', 'replace_default_with_xdefault', 10 );

function replace_default_with_xdefault( $hreflang_items ) {

	$default_lang = apply_filters( 'wpml_default_language', null );

	if ( array_key_exists( $default_lang, $hreflang_items ) ) {

		$hreflang_items['x-default'] = $hreflang_items[ $default_lang ];

		unset( $hreflang_items[ $default_lang ] );

	}
	return $hreflang_items;
}

This code will remove the en hreflang and add x-default for the URL without language parameter, I hope this would help resolve the issue. I have not tested this with SEMrush, please run a test and let me know the results.

Kind regards
Raja

December 24, 2019 at 4:29 am #5187991

marketingV

I have added above code in functions.php file. I will let you know after checking.

Thanks.

December 24, 2019 at 11:40 am #5189393

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sure. I will await your response.

January 4, 2020 at 3:57 am #5232873

marketingV

SEMrush is showing 288 errors now. Previous was 319 errors.

January 6, 2020 at 5:02 am #5238485

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Can you please check with SEMRush what exactly is needed to fix the issue. As far as i can see the pages has self referencing tags and also with the fix form the code now it has x-default tag, If you can help us with more insights it would be much helpful.

Kind regards
Raja

January 8, 2020 at 7:03 am #5251605

marketingV

SEMrush is showing a slash('/') end of each URL but in website don't have slash end of URLs. It may create this issue. I tried to set slash at the end of URL placing code in .htdocs file but couldn't set slash end of URLs.

Can you help me to place a slash end of URL? Then we could see this issue can be solved or not.

January 9, 2020 at 8:06 am #5259311

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

You can add a trailing slash to all the url from your wordpress admin.
Go to your WordPress Dashboard -> Settings -> Permalinks.

If you choose a “Custom Structure” for your permalinks, then you can either include or remove the trailing slash at the end. Please refer to the screenshot. Changing the premalink will change the hreflang as well.

Let me know if that helps.

Kind regards
Raja

wordpress-permalink-and-trailing-slash-settings.png
January 9, 2020 at 8:36 am #5259493

marketingV

Already I have done this. Permalinks structure is set by /%postname%/ . But still don't have trailing slash end of URL.

parmalink.png
January 9, 2020 at 11:07 am #5260883

marketingV

This problem is solved. Now trailing slash is set at the end of URLs. A plugin was preventing to show the slash.

January 10, 2020 at 4:50 am #5266589

Raja Mohammed
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

That was great to hear, Could you please confirm whether the issue still persists in SEMRush, Would you mind sharing the plugin details which was preventing the slash that would help other customers looking for a similar solution.

Kind regards
Raja

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.