Skip Navigation

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

Problem:
The client is experiencing issues where category pages are not connected with their translated equivalents, and hreflang tags are missing on paginated category pages. Additionally, the language switcher redirects to the root category page instead of the corresponding translated category page.
Solution:
We recommended inserting custom PHP code into the theme's functions.php file to address the URL issues with the language switcher on paginated category pages. Here is the code you should add:

add_filter('icl_ls_languages', 'wpml_ls_filter');
function wpml_ls_filter($languages) {
    global $sitepress;
    $url = $_SERVER['REQUEST_URI'];
    $tokens = explode('/', $url);
    $l = $tokens[sizeof($tokens)-2];
    $sl = $tokens[sizeof($tokens)-3];
    $cl = $sl.'/'.$l.'/';
    if($sl == 'page') {
        foreach($languages as $lang_code => $language) {
            $languages[$lang_code]['url'] = str_replace($languages[$lang_code]['url'], $languages[$lang_code]['url'].$cl, $languages[$lang_code]['url']);
        }
    }
    return $languages;
}

For the hreflang tags issue, it was determined by our 2nd Tier Support that this is a default behavior and indexing paginated archive pages is not recommended. If you still require hreflang tags on paginated pages, it would require custom programming, which is outside our support scope. We recommend consulting with one of our certified partners: http://wpml.org/documentation/support/wpml-contractors/

If this solution does not resolve your issue or seems irrelevant, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If needed, please open a new support ticket at 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 8 replies, has 2 voices.

Last updated by Kor 1 year ago.

Assisted by: Kor.

Author Posts
June 11, 2024 at 3:45 pm #15727436

clementV-3

Background of the issue:
I am trying to connect category pages on my site hidden link with their translated equivalents. The category pages like hidden link are not connected with the translated equivalent, here hidden link. I am following the documentation at https://wpml.org/documentation/getting-started-guide/translating-post-categories-and-custom-taxonomies/.

Symptoms:
The category pages do not have a URL hreflang and clicking on the Language Switcher redirects to the root category page (hidden link).

Questions:
Is it expected behavior that the category pages are not connected with their translated equivalents?
How can I solve the issue of category pages not having a URL hreflang and the Language Switcher redirecting to the root category page?

June 11, 2024 at 3:52 pm #15728060

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your patience.

Here is the ticket and I will need to closely examine your website. Therefore, I will require temporary access (WP-Admin and FTP) to a test site where the problem has been replicated, if possible. This will enable me to provide better assistance and determine if any configurations need to be modified.

Please note that it is important to have a backup for security purposes and to prevent any potential data loss. You can use the UpdraftPlus plugin (https://wordpress.org/plugins/updraftplus/) to fulfill your backup requirements.

Your upcoming reply will be treated with confidentiality and will only be visible to you and me.

✙ To resolve the issue, I may need your consent to deactivate and reactivate plugins and the theme, as well as make configuration changes on the site if necessary. This emphasizes the significance of having a backup.

June 12, 2024 at 4:20 pm #15732799

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thank you for your patience.

I regret any inconvenience caused, but to proceed with troubleshooting, I kindly ask for a snapshot of the site. Alternatively, with your permission, I can create one myself. For this purpose, I typically recommend using the free plugin "Duplicator." If you're already familiar with Duplicator (https://wordpress.org/plugins/duplicator/), please skip the following steps and simply send me the archive file you downloaded.

To guide you further, please adhere to these instructions:

1. View the Duplicator instructions video: hidden link

2. Consult WPML's instructions on providing supporters with a copy of your site: https://wpml.org/faq/provide-supporters-copy-site/

3. If the archive file exceeds 400MB, please use Duplicator's file filters to exclude cache, wp-uploads directory, media, and archive files.

Once you have the archive file ready, kindly share the link with us. You can utilize platforms like Google Drive, Dropbox, or similar for file sharing, as the snapshot file might be large.

Please note that your next reply will be private, visible only to you and me. You can paste the file link there. Rest assured that once the issue is resolved, I will delete the local site.

June 18, 2024 at 10:07 am #15748342

clementV-3

Hi,
I can create a staging website if you want and give you access to it. You will be able to change pretty much anything, but the premium plugins may not be fully active.
Does it work for you?

June 18, 2024 at 4:14 pm #15750086

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your reply.

Yes, that could work. I've enabled the private reply option for you.

June 25, 2024 at 7:23 pm #15824806

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your patience.

Please insert the custom PHP code below into your theme's functions.php file to fix this. I've added it on your staging site and it works now hidden link when switching to another language.

add_filter('icl_ls_languages', 'wpml_ls_filter');
function wpml_ls_filter($languages) {
global $sitepress;
$url = $_SERVER['REQUEST_URI'];
$tokens = explode('/', $url);
$l = $tokens[sizeof($tokens)-2];
$sl = $tokens[sizeof($tokens)-3];
$cl = $sl.'/'.$l.'/';
if($sl == 'page'){
foreach($languages as $lang_code => $language){
$languages[$lang_code]['url'] = str_replace($languages[$lang_code]['url'],$languages[$lang_code]['url'].$cl,$languages[$lang_code]['url']);
}
}
return $languages;
}
July 2, 2024 at 2:06 pm #15876193

clementV-3

Hi,
Thank you for this fix.
I've added to the live website and I can switch correctly from English to French and vice versa.

However, there is still not the hreflang tags when it's not the first page of the category.

Best,

July 2, 2024 at 2:48 pm #15876416

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thanks for your reply.

It looks like a default behavior for categories with paginations. hidden link . I can see the missing hreflang

Please allow me to check with our 2nd Tier Support to see if they have any way to achieve this.

Login : hidden link

July 3, 2024 at 9:14 am #15882740

Kor
WPML Supporter since 08/2022

Languages: English (English )

Timezone: Asia/Singapore (GMT+08:00)

Thank you for your patience.

Upon review by our 2nd Tier Support, it appears that the hreflang issue you mentioned is a default behavior, where the hreflang tags may not be included in the source code for SEO purposes. It's also noted that indexing paginated archive pages is not recommended.

For example, you can see more details here: hidden link

If you still require this feature, it would necessitate custom programming, which falls outside the scope of our support services. We recommend contacting one of our certified partners from this list: http://wpml.org/documentation/support/wpml-contractors/

Please review the guidelines here before proceeding: http://wpml.org/documentation/support/wpml-contractors/guidelines-for-people-looking-for-consulting-help/

Additionally, I will escalate your request as a feature request for review by our developers and management.

July 3, 2024 at 12:56 pm #15884480

clementV-3

Hi,
Thank you for your answer.
I was wondering whether it was expected behavior mainly for SEO purposes so I'm good if that's the correct way of doing it.
Best,