Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client is experiencing incorrect hreflang attributes for custom post types (CPTs) on their multilingual website. The English and x-default URLs are not displaying correctly when checked in Italian, despite being fine in English.
Solution:
We recommend downgrading to the stable release of WPML if you're encountering similar hreflang issues with custom post types. Specifically, the client was advised to install WPML 4.6.9 stable release instead of the beta version they were using. You can download the latest stable versions from the My Account -> Downloads section of the WPML website.
Please note that this solution might not apply to your situation if it's outdated or not relevant to your case. If the problem persists after trying the suggested steps, we highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please don't hesitate to open a new support ticket. For further help, you can reach out to us on the WPML support forum.

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.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Andrey 1 year, 1 month ago.

Assisted by: Andrey.

Author Posts
March 19, 2024 at 5:46 pm #15428180

luigiB-2

Hello, I am noticing issues with hreflang for this website.
I have several CPTs added via code, translated with WPML. If I check the hreflangs in English they are fine; if I check them in Italian this is the result:

<link rel="alternate" hreflang="en" href="hidden link" />
<link rel="alternate" hreflang="it" href="hidden link" />
<link rel="alternate" hreflang="x-default" href="hidden link" />

The english and x-default link should be
hidden link
This happens for every CPT, with or without Yoast SEO active, after saving permalinks and posts too.

I am trying to:
have hreflangs properly displayed to help SEO and multilanguage content
Link to a page where the issue can be seen:
hidden link
I expected to see:

<link rel="alternate" hreflang="en" href="hidden link" />
<link rel="alternate" hreflang="it" href="hidden link" />
<link rel="alternate" hreflang="x-default" href="hidden link" />

Instead, I got:
<link rel="alternate" hreflang="en" href="hidden link" />
<link rel="alternate" hreflang="it" href="hidden link" />
<link rel="alternate" hreflang="x-default" href="hidden link" />

Thank you!

March 19, 2024 at 8:42 pm #15428871

Andrey
WPML Supporter since 06/2013

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+03:00)

Can you please provide details on how you created your custom post type (CPT)? You can share a code. Have you tried disabling all plugins except WPML plgins to see if the issue persists?

Additionally, could you share screenshots of the custom post and its translations?

It's important to backup your database before making any changes.

March 20, 2024 at 9:07 am #15430031

luigiB-2

Sure, thank you for you reply.
This is the code to create the CPT:

register_post_type( 'success-case', array(
'label' => __( 'Success case', 'qzrstudio' ),
'description' => __( 'Success case', 'qzrstudio' ),
'labels' => array(
'name' => __( 'Success case', 'qzrstudio' ),
'singular_name' => __( 'Success case', 'qzrstudio' ),
'menu_name' => __( 'Success case', 'qzrstudio' ),
'all_items' => __( 'Tutti i success case', 'qzrstudio' ),
'view_item' => __( 'Vedi success case', 'qzrstudio' ),
'add_new_item' => __( 'Aggiungi success case', 'qzrstudio' ),
'add_new' => __( 'Aggiungi success case', 'qzrstudio' ),
'edit_item' => __( 'Modifica success case', 'qzrstudio' ),
'update_item' => __( 'Aggiorna success case', 'qzrstudio' ),
'search_items' => __( 'Cerca success case', 'qzrstudio' ),
'not_found' => __( 'Non trovato', 'qzrstudio' ),
'not_found_in_trash' => __( 'Non trovato nel cestino', 'qzrstudio' ),
),
'supports' => array( 'title', 'thumbnail', 'editor', 'custom-fields', 'excerpt', 'revisions'),
'hierarchical' => false,
'rewrite' => array( 'with_front' => false),
'public' => true,
'show_ui' => true,
'show_in_rest' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'menu_icon' => 'dashicons-yes-alt',
) );

Please bear in mind that this happens also on other CPTs on the same website, but not to pages and posts as far as I can see.
I tried to toggle "has_archive" on true/false as another user here said it solved its issue, but without results.

I disabled other plugins without results, even after saving permalinks again.
Thank you again,
Luigi

March 20, 2024 at 7:04 pm #15433475

Andrey
WPML Supporter since 06/2013

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+03:00)

Thank you for your feedback, Luigi. I appreciate it. Can you please provide screenshots of how you created and translated those custom posts? What are results with any default theme?

To help further diagnose the problem, I suggest downloading our Toolset Types plugin from your account: https://wpml.org/account/downloads/. Once you have downloaded and installed the plugin, you can create a test custom post type and custom posts under it. This will help us determine if the issue is related to your code or if there is a general problem with custom post types in your installation.

Please backup your database before making any changes.

March 21, 2024 at 8:58 am #15434992

luigiB-2

Hello Andrey, I created a CPT via Tooset Types plugin and the result is the same, even after refreshing permalinks and changing the theme to Twenty Twenty One.
Here is the URL in English, where hreflangs are correct:
hidden link
This is the URL in Italian:
hidden link
In Italian hreflangs are incorrect:
<link rel="alternate" hreflang="en" href="hidden link" />
<link rel="alternate" hreflang="it" href="hidden link" />
<link rel="alternate" hreflang="x-default" href="hidden link" />
Please find attached some screenshots (I don't know what could be helpful to debug this issue).

screenshot-mia-care.io-2024.03.21-09_56_54.png
screenshot-mia-care.io-2024.03.21-09_57_15.png
screenshot-mia-care.io-2024.03.21-09_57_42.png
screenshot-mia-care.io-2024.03.21-09_57_55.png
screenshot-mia-care.io-2024.03.21-09_41_28.png
screenshot-mia-care.io-2024.03.21-09_42_07.png
March 22, 2024 at 9:58 pm #15442561

Andrey
WPML Supporter since 06/2013

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+03:00)

Thank you for providing your tests and feedback. I find it strange that I am unable to replicate the issue you are facing. However, I noticed that you are using WPML beta 4.6.10-b.1 plugin. Can you please try installing WPML 4.6.9 stable release and check if the issue still persists?

You can find the latest released versions under "My Account -> Downloads" on this website. Please let me know how it goes.