WPML
Status
Waiting for author
Related plugin/theme
WP User Manager
Topic tags
Compatibility

Overview of the issue

When using WP User Manager plugin, switching languages on a public user profile page (e.g. /profile/username) redirects to the main profile page (e.g. /fr/profil/) instead of the specific translated profile (e.g. /fr/profil/username).

Workaround

Please, make sure of having a full site backup of your site before proceeding.


  • Edit your theme’s functions.php file and add the following function:
    // 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;
    } );

All known issues →