Home›Support›English Support›[Resolved] Split: the language switcher is not leading to the pages as before
[Resolved] Split: the language switcher is not leading to the pages as before
This thread is resolved. Here is a description of the problem and solution.
Problem: The client needed the Finnish, Latvian, and Lithuanian flags in their WPML language switcher to link to external partner sites instead of internal translations, but the existing jQuery code was not functioning. Solution: We recommended adding a custom function to the
functions.php
file of the client's theme. This function modifies the language switcher to include external links for the specified languages. Here is the code to implement:
Please ensure to back up your site fully before implementing this solution. If this solution does not resolve your issue or seems outdated, we recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If further assistance is needed, please open a new support ticket.
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.
I managed to subscribe but now the issue is that the language switcher (flags on the top right corner of the site) are not leading to the pages as before. Please check this link hidden link and if to then click on the three flags (Finnish, Latvian, Lithuanian) on the top right corner you will see that it doesn’t work. I don’t know what exactly happened as it was working before upgrading to paid version of WPML. I have added the correct links where these flag buttons should lead to in the Customize - Settings - Custom code section.
Welcome!
I'm the fox of Veebimajutus.ee and welcome you here. Website is not ready yet, but the owner of the page is working hard to bring it to you as quickly as possible.
Please see the attached screenshot.
If you have a folder named /fi/ in your WordPress installation, this might be the reason for this. You should delete this folder because this might interfere with WPML's Language URL format of Languages Directories.
**** Important! Please make a full site backup (files and DB) before you proceed with those steps****
Other than that, please ensure that the homepage for the Finnish, Latvian, and Lithuanian languages is published.
If it does not help and you need further help with this, please share the access details to your site with me. I'm enabling a private message for the following reply. Privacy and Security Policy
We have strict policies regarding privacy and access to your information. Please see: https://wpml.org/purchase/support-policy/privacy-and-security-when-providing-debug-information-for-support/ **IMPORTANT**
- - Please backup the site files and database before providing us access. --
-- If you have a staging site where the problem can be reproduced, it is better to share access to the staging site.--
Let me explain in more detail.
Those flags on the top right corner were working a bit differently for us.
Only the Estonian and English flags lead to our actual website translated sections.
The Finnish, Latvian and Lithuanian flags are supposed to link to an external site of our partners. These are located in other server and are not part of our WordPress.
So we have previously added this code to our Customize - Settings - Custom code section:
There you see those links where each flag should direct to.
It doesn't work anymore. Do you know can we solve this is with the flags? If we don't have those translations in these languages but want those flags to direct to our partners external websites, what should we do?
NB. I haven't yet created a back-up of anything. Do you need to log in to our WordPress to check the possible solutions?
If the Finnish, Latvian, and Lithuanian flags are supposed to link to external sites, then you should remove them from WPML. In other words, they should not be added as secondary languages. This can be done in WPML -> Languages -> Site Languages, and click the Add/Remove Languages button.
Then, you need to create a custom Language Switcher by following the instructions in our guide here.
The above guide only gives some simple examples. You will need your custom Language Switcher to combine Estonian and English (the languages added by WPML) and the external links you need to the Finnish, Latvian, and Lithuanian websites.
If you have further questions or doubts about what we explain in the above guide, we will happily answer them. If something is not working in the custom Language Switcher you created, we will be glad to take a look and say what might be the problem.
Otherwise, if you need further help with what you are trying to achieve, I would suggest you consider contacting one of our certified partners from this link:
Hello
Thanks for the info.
But can I create external links to the Finnish, Latvian, and Lithuanian websites by following this guide that you sent? I didn't see there this option to add an external link behind the language flag.
As I mentioned, you will need custom work to achieve this, which is out of the scope of our support forum. However, I asked our second-tier supporters if they could provide a sample code for your needs. I'll update you here once I have their reply.
Hi
Thanks for the code.
I added it to the page, the flags now appeare but they still don't lead to the links provided. Now I get an error message that nothing appears on this link and the URL is hidden link
Before sharing the code with you, I tested it, and it worked on my test site.
It looks like some HTML tags got added to your custom code. Please see the attached screenshot. Without seeing your code, I cannot tell what went wrong. I also can't see the problem on your site. The other languages do not show.
If you share with me the code you added to the functions.php file of your theme, I can look to see if I can spot the problem.
Hi
Please see here the screenshot of how I added the code to functions.php file.
I also added a screenshot showing how the flags are now there but the links for LV, LT and FIN don't work.
Thanks
The problem is evident in your screenshot of the code.
The part of the code that is supposed to include the link to your other website is like this:
'url' => '<em><u>hidden%20link</u></em>'
When, for example, it supposes to be like this :
'url' => '<em><u>hidden link</u></em>',
(Each link should be to your other websites.)
You probably copied my code when you were not logged in to your wpml.org account and when you opened the ticket link in the email. In this case, all links are hidden. See how the code looks when you are logged in. Please see the attached screenshot. Compare it to the code on your site or screenshot, and you'll see the mistake.
You must be logged in to your wpml.org account before you copy my code. For your convenience, here is the code again.
function custom_language_switcher_links( $languages ) {
// Add the first external link
$languages['external_1'] = array(
'url' => '<em><u>hidden link</u></em>',
'native_name' => 'Suomi',
'translated_name' => 'Finnish',
'country_flag_url' => 'https://cdn.wpml.org/wp-content/plugins/sitepress-multilingual-cms/res/flags/fi.svg',
'language_code' => 'fi',
'code' => 'fi'
);
// Add a second external link
$languages['external_2'] = array(
'url' => '<em><u>hidden link</u></em>',
'native_name' => 'Latviešu',
'translated_name' => 'Latvian',
'country_flag_url' => 'https://cdn.wpml.org/wp-content/plugins/sitepress-multilingual-cms/res/flags/lv.svg',
'language_code' => 'lv',
'code' => 'lv'
);
// Add a third external link
$languages['external_3'] = array(
'url' => '<em><u>hidden link</u></em>',
'native_name' => 'Lietuvių',
'translated_name' => 'Lithuanian',
'country_flag_url' => 'https://cdn.wpml.org/wp-content/plugins/sitepress-multilingual-cms/res/flags/lt.svg',
'language_code' => 'lt',
'code' => 'lt'
);
return $languages;
}
add_filter( 'icl_ls_languages', 'custom_language_switcher_links' );