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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Mateus Getulio 4 months ago.

Assisted by: Mateus Getulio.

Author Posts
July 5, 2024 at 2:39 pm #15899036

dejanP-5

Background of the issue:
On our site with approximately 300 pages (including 220+ blog posts), we only needed to translate 26 pages into English using WPML. We enabled hreflang tags, which work well for those dual language pages. However, the issue is that the remaining 250+ single-language pages also have unnecessary hreflang tags pointing to their own language and the x-default.

Symptoms:
Unnecessary hreflang tags are being displayed on single-language pages, potentially causing SEO issues and search engine confusion.

Questions:
Could you please provide guidance on how to configure WPML to apply hreflang tags only to translated pages, and not to single-language pages, which are majority?

July 8, 2024 at 12:03 pm #15912900

dejanP-5

Meanwhile, we have tried putting this proposed custom code to functions.php, but no avail, hreflang still shows for single language pages:

add_filter('wpml_hreflangs', function($hreflang_items) {
if (is_singular()) {
$post_type = 'post_' . get_post_type();
$translations = apply_filters('wpml_get_element_translations', [], apply_filters('wpml_element_trid', false, get_the_ID(), $post_type), $post_type);
if (empty($translations)) {
if (isset($x_default, $hreflang_items[$x_default])) {
unset ($hreflang_items['x-default']);
}
}
}
return $hreflang_items;
});

July 8, 2024 at 7:32 pm #15915482

Mateus Getulio
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

I would like to request temporary access (wp-admin and FTP) to your site to take better look at the issue. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

Our Debugging Procedures

I will be checking various settings in the backend to see if the issue can be resolved. Although I won't be making changes that affect the live site, it is still good practice to backup the site before providing us access. In the event that we do need to debug the site further, I will duplicate the site and work in a separate, local development environment to avoid affecting the live site.

Privacy and Security Policy

We have strict policies regarding privacy and access to your information. Please see:
https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/

**IMPORTANT**

- Please make a backup of site files and database before providing us access.
- If you do not see the wp-admin/FTP fields this means your post & website login details will be made PUBLIC. DO NOT post your website details unless you see the required wp-admin/FTP fields. If you do not, please ask me to enable the private box. The private box looks like this: hidden link

Please, let me know if you need any additional details. Have a nice day.

The topic ‘[Closed] Hreflang Tags Displayed on Single-Language Pages’ is closed to new replies.