WPML获取原文译文永久链接异常:德国IP重定向插件问题
Alright, let's tackle this WPML permalink problem you're dealing with. It’s super annoying when you expect www.mysite.com/de/kontakt/ but end up with www.mysite.com/de/contact/ instead—let’s break down the most likely fixes:
1. Verify Page Translation & Slug Setup First
First things first, double-check the basics:
- Make sure your contact page has a published German translation where the slug is explicitly set to
kontakt. Sometimes drafts or incomplete translations won’t sync the slug properly. - Head to WPML → String Translation and search for the page slug ("contact"). Ensure the German translation is set to "kontakt" and marked as complete. WPML might not auto-translate slugs unless you’ve configured that, so this step is crucial.
2. Ensure You’re Using wpml_permalink() Correctly
It’s easy to miss a parameter that causes this issue. Make sure you’re passing both the original page ID and the target language code explicitly:
// Get the original English contact page ID $original_contact_id = get_page_by_path('contact')->ID; // Generate the German permalink $german_contact_link = wpml_permalink($original_contact_id, 'de');
Avoid relying on the current language context—specifying 'de' directly ensures WPML knows exactly which language version to fetch.
3. Flush WPML Cache & Permalinks
WPML and WordPress both cache rewrite rules and language data, which can cause stale slugs to stick around:
- Go to WPML → Support → Troubleshooting and click "Clear WPML cache" to wipe any cached language-related data.
- Then head to Settings → Permalinks, scroll to the bottom, and click "Save Changes" (no need to edit anything—this just refreshes WordPress’s rewrite rules to pick up the new slug).
4. Rule Out Plugin/Theme Conflicts
Sometimes other plugins or your theme can interfere with WPML’s permalink generation:
- Temporarily disable all non-WPML plugins, then test your
wpml_permalink()call again. If it works, re-enable plugins one by one to find the culprit. - Switch to a default WordPress theme (like Twenty Twenty-Four) to see if the issue goes away. If it does, your theme might have a function overriding WPML’s permalink logic.
5. Fallback: Use wpml_object_id to Get the German Page Directly
If wpml_permalink() still isn’t cooperating, try a more direct approach by fetching the German page ID first, then generating the permalink:
$original_contact_id = get_page_by_path('contact')->ID; // Get the German version of the page ID $german_contact_id = apply_filters('wpml_object_id', $original_contact_id, 'page', true, 'de'); // Generate the permalink using the German page ID $german_contact_link = get_permalink($german_contact_id);
This method skips the wpml_permalink() function entirely and uses WPML’s core filter to grab the correct translated page, which often resolves slug mismatch issues.
6. Check WPML Language Redirect Settings
Just to be safe, make sure WPML’s built-in redirects aren’t conflicting with your custom plugin:
- Go to WPML → Languages → Language Switcher Options and check if "Redirect visitors to their browser's language" is enabled. While your plugin should take priority, disabling this temporarily can help rule out interference.
内容的提问来源于stack exchange,提问作者madhushankarox

