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: Custom Work
This topic contains 1 replies, has 0 voices.
Last updated by Andreas W. 1 week ago.
Assisted by: Andreas W..
Author | Posts |
---|---|
August 6, 2025 at 3:25 pm #17300182 | |
chiragA-3 |
Background of the issue: I’m looking for help customising the behaviour of the WPML language switcher. We currently manage two WordPress sites: A global site hosted on glginsights.com, which includes English, Japanese, Korean, and German. A China site hosted separately on glginc.cn. The content across both sites is very similar — essentially translated versions of each other — and we maintain consistent permalinks between them. We’d like to configure the language switcher so that: Selecting a different language redirects users between the two domains, depending on the language. The switcher simply replaces the domain and language slug, keeping the rest of the permalink intact. Is there a recommended way to achieve this setup using WPML, or would you suggest any custom approach? Thanks in advance for your guidance! Symptoms: Questions: |
August 8, 2025 at 3:22 pm #17305852 | |
Andreas W. WPML Supporter since 12/2018 Languages: English (English ) Spanish (Español ) German (Deutsch ) Timezone: America/Lima (GMT-05:00) |
Hi Chirag, Thanks for the detailed explanation. You're correct that WPML doesn’t natively support switching languages across two separate WordPress installs (glginsights.com and glginc.cn). The built-in language switcher only works within a single site, based on translations stored in that site's database. However, since your permalinks are consistent across both domains, you can implement a custom redirect using the wpml_language_has_switched hook. This hook fires after WPML switches the language context, and you can use it to redirect users to the corresponding page on the other domain. Here’s a basic example, which I did not test myself, but it should clarify how the hook operates: add_action( 'wpml_language_has_switched', function( $lang ) { // Only run on frontend if ( is_admin() || wp_doing_ajax() ) return; $current_uri = $_SERVER['REQUEST_URI']; if ( $lang === 'zh' ) { wp_redirect( '<em><u>hidden link</u></em>' . $current_uri ); exit; } elseif ( in_array( $lang, [ 'en', 'ja', 'ko', 'de' ] ) ) { wp_redirect( '<em><u>hidden link</u></em>' . $lang . $current_uri ); exit; } }); Notes: You’ll want to scope this logic to specific templates or routes to avoid interfering with admin or AJAX requests. You may also need to adjust language codes (zh, ja, etc.) to match your WPML configuration. Further, please kindly note that this is a custom code request, and our supporters are usually not expected to provide custom code solutions. If you receive such solutions on the forum, then this is due to goodwill and occurs voluntarily. Best regards |