Skip to content Skip to sidebar

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

Problem:
If you're trying to switch languages on a profile page using the WPML language switcher, but instead of being redirected to the corresponding profile page in the other language, you are redirected to a generic profile page or a warning page.
Solution:
We recommend backing up your site before making any changes. Then, edit your theme's functions.php file and add the following code at the end:

// WPML Workaround for compsupp-8195<br />// Preserve WPUM profile sub-path when switching languages with WPML.<br />add_filter( 'icl_ls_languages', function( $languages ) {<br />    // Only run if WPUM<br />    if ( ! function_exists( 'wpum_get_core_page_id' ) ) {<br />        return $languages;<br />    }<br /><br />    // Get profile info from query vars<br />    $queried_profile = get_query_var( 'profile', false );<br />    if ( ! $queried_profile ) {<br />        return $languages;<br />    }<br /><br />    // Build the trailing path from query vars<br />    $trailing = '/' . rawurlencode( $queried_profile );<br /><br />    // Add tab and pagination if present<br />    $tab = get_query_var( 'tab' );<br />    if ( $tab ) {<br />        $trailing .= '/' . rawurlencode( $tab );<br />    }<br />    $paged = get_query_var( 'paged' );<br />    if ( $paged ) {<br />        $trailing .= '/page/' . rawurlencode( $paged );<br />    }<br /><br />    // Append to each language URL<br />    foreach ( $languages as $key => $lang ) {<br />        if ( empty( $lang['url'] ) ) {<br />            continue;<br />        }<br />        $languages[$key]['url'] = rtrim( $lang['url'], '/' ) + $trailing;<br />    }<br /><br />    return $languages;<br />} );

This solution might be outdated or not applicable to your case. 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 this does not resolve your issue, please open a new support ticket.

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 2 replies, has 0 voices.

Last updated by chrisL-17 4 weeks, 1 day ago.

Assisted by: Lucas Vidal de Andrade.

Author Posts
November 3, 2025 at 8:25 pm #17543396

chrisL-17

Background of the issue:
I am trying to view an individual profile page in English, such as hidden link, and switch to the French version using the language switcher menu. I expect to be taken to the French version of the user's profile page, hidden link.

Symptoms:
Instead of being directed to the French version of the user's profile page, the link redirects to hidden link, which is either my profile page as a logged-in user or a warning page stating 'this page is available only to logged-in users'.

Questions:
Why does the language switcher not redirect to the correct French profile page?
How can I ensure the site functions in both English and French for all pages, including profile pages?

November 4, 2025 at 1:35 pm #17545952

Lucas Vidal de Andrade
WPML Supporter since 11/2023

Languages: English (English )

Timezone: Europe/Vienna (GMT+01:00)

Hello there,

Thank you for sharing the details.

I would like to look at this directly on your site. For this I would need temporary access (WP-Admin and FTP) to your site, preferably to a test/staging site where the problem has been replicated if possible.

The required fields can be found below the comments section. The information you enter is private, i.e. only you and I can see it and have access to it.

I may need to replicate your website locally. To do this, I need to temporarily install a plugin called "Duplicator" or "All in One WP Migration" on your website. This will allow me to create a copy of your website and content. Once the issue is resolved, I will delete the local website. Let me know if this works for you.

IMPORTANT

Please make a backup copy of the site files and database before giving us access.

- If you do not see the wp-admin/FTP fields, this means your post and site login details are being made PUBLIC. DO NOT post your website details if you do not see the required wp-admin/FTP fields. If you do not, ask me to enable the private box. The private box looks like this:

hidden link

November 4, 2025 at 3:10 pm #17546456

Nicolas V.
Supporter

Languages: English (English ) French (Français )

Timezone: America/Lima (GMT-05:00)

Hi Chris,

Let me jump in here, as I previously worked with Marcel on your earlier ticket. I used the same sandbox we set up before to review the code in question.

The plugin uses a routing abstraction (cortex.routes + QueryRoute) to add URL patterns. This means it doesn't rely on WordPress’s native add_rewrite_rule function.

Workaround:
- Make sure to back up your site before making any changes
- Edit your theme's functions.php file and add the following at the end:

// WPML Workaround for compsupp-8195
// Preserve WPUM profile sub-path when switching languages with WPML.
add_filter( 'icl_ls_languages', function( $languages ) {
    // Only run if WPUM
    if ( ! function_exists( 'wpum_get_core_page_id' ) ) {
        return $languages;
    }

    // Get profile info from query vars
    $queried_profile = get_query_var( 'profile', false );
    if ( ! $queried_profile ) {
        return $languages;
    }

    // Build the trailing path from query vars
    $trailing = '/' . rawurlencode( $queried_profile );

    // Add tab and pagination if present
    $tab = get_query_var( 'tab' );
    if ( $tab ) {
        $trailing .= '/' . rawurlencode( $tab );
    }
    
    $paged = get_query_var( 'paged' );
    if ( $paged ) {
        $trailing .= '/page/' . rawurlencode( $paged );
    }

    // Append to each language URL
    foreach ( $languages as $key => $lang ) {
        if ( empty( $lang['url'] ) ) {
            continue;
        }
        $languages[$key]['url'] = rtrim( $lang['url'], '/' ) . $trailing;
    }

    return $languages;
} );

You can test it by login into the sandbox: hidden link
And then test it with these two profiles:
- hidden link
- hidden link

November 7, 2025 at 2:36 pm #17557612

chrisL-17

That works a treat. Thank you so much!