Chuyển đến nội dung Chuyển đến thanh bên

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

Để lại trả lời

Vui lòng giữ đúng chủ đề và tôn trọng người khác. Nếu bạn cần trợ giúp với các vấn đề không liên quan đến bài đăng này, hãy sử dụng Diễn đàn Hỗ trợ của chúng tôi để bắt đầu trò chuyện hoặc gửi vé hỗ trợ.

Bạn có thể sử dụng các thẻ này:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>