ข้ามไปยังเนื้อหาหลัก ข้ามไปยังแถบด้านข้าง

Waiting for author

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;
    } );
    

แสดงความคิดเห็น

โปรดอยู่ในหัวข้อและให้ความเคารพผู้อื่น หากคุณต้องการความช่วยเหลือในประเด็นที่ไม่เกี่ยวข้องกับโพสต์นี้ ให้ใช้ฟอรัมสนับสนุนของเราเพื่อเริ่มการแชทหรือส่งตั๋ว.

คุณสามารถใช้แท็กเหล่านี้:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>