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 1 reply, has 2 voices.

Last updated by Long Nguyen 11 months ago.

Assisted by: Long Nguyen.

Author Posts
October 26, 2023 at 9:09 am #14668383

martinW-39

I would like to add multiple hreflang tags for the same language (e.g. de-DE and de-CH) pointing on the same URL, but it seems that WPML only allows one tag per language by default.

Could you please let me know if there is a way to fix this problem or if there is a recommended procedure to add multiple hreflang tags for the same language? If it's not possible, are there any third party plugins or solutions you can recommend? Thank you.

October 27, 2023 at 4:22 am #14674975

Long Nguyen
Supporter

Languages: English (English )

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

Hi Martin,

Thank you for contacting WPML support, I'd be happy to help you with this issue.

By default, WPML supports one hreflang tag for one language. If you want to add more hreflang tags for a language, you can try to use the filter hook "wpml_hreflangs". This is for example:

add_filter( 'wpml_hreflangs', function( $hreflang_items ) {
	if ( is_array( $hreflang_items ) ) {
		foreach( $hreflang_items as $hreflang_code => $hreflang_url ) {
			if( $hreflang_code == 'de' ) {
				$hreflang_items['de-CH'] = $hreflang_items['de'];
			}
		}
	}
	return $hreflang_items;
} );

Note: I would like to inform you that helping you with custom code, is out of the scope of WPML. If you are not able to accomplish this, I would recommend you contact one of our certified partners who will be more than happy to help you with this. In this link, you will find a list of our certified partners: https://wpml.org/contractors/

Look forward to your reply.
Thanks

The topic ‘[Closed] Multiple hreflang tags for one language and one url’ is closed to new replies.