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.
This topic contains 2 replies, has 1 voice.
Last updated by Prosenjit Barman 1 week, 5 days ago.
Author | Posts |
---|---|
December 19, 2024 at 2:30 pm #16530554 | |
pimv-12 |
Background of the issue: '; $count = 0; $total_languages = count($languages); foreach ($languages as $lang_code => $language) { // Get the translated URL for the current page $translated_url = apply_filters('wpml_permalink', $current_url, $lang_code); if (!$language['active']) { $output .= '' . strtoupper($lang_code) . ''; } else { $output .= '' . strtoupper($lang_code) . ''; } // Append separator except for the last language if ($count < $total_languages - 1) { $output .= ' / '; } $count++; } $output .= '
'; return $output; } } return ''; // Return empty string if WPML is not active } add_shortcode('custom_language_switcher', 'custom_language_switcher_shortcode'); Symptoms: Questions: |
December 19, 2024 at 2:38 pm #16530584 | |
pimv-12 |
I still need help |
December 20, 2024 at 7:14 am #16532218 | |
Prosenjit Barman Supporter
Languages: English (English ) Timezone: Asia/Dhaka (GMT+06:00) |
Hi There! Before this thread gets assigned to my colleague, I'd like to offer some initial guidance or potential solutions. I’ve reviewed the code and noticed that you’re using the "wpml_permalinks" hook. In cases where links are not directed correctly, we always recommend resetting the permalink structure. You can do this by navigating to "Settings > Permalinks" and simply saving the settings again. Could you please try this and let us know if it resolves the issue? If the issue still persists, The problem could lie in the way the translated URL is generated for other languages. In your original code, you're using the `apply_filters('wpml_permalink', $current_url, $lang_code)` function to get the translated URL for the current page. However, this function does not always return the correct translated URL, especially if the current page is not translated yet. So, before generating the URL, ensure the current page or post ID is passed through the `wpml_object_id` filter. This will retrieve the corresponding translated page or post ID. Once the translated ID is obtained, use the `wpml_permalink` hook to generate the correct translated link. If no translation is available, fall back to the main URL. Could you please try to modify the code to use the current page's URL when the current language is active? As providing support for the custom code is beyond our support scope, we can only help by providing guidance or suggestions that might help. For direct coding assistance, consider hiring a developer, experienced in customizing WPML from here: https://wpml.org/contractors/ I hope you can understand. If you have any other questions or need clarification, feel free to reach us. We'll be happy to help. Best regards, |