Home›Support›English Support›[Resolved] Is it posible to add a manual URL, website to your language switzer?
[Resolved] Is it posible to add a manual URL, website to your language switzer?
This thread is resolved. Here is a description of the problem and solution.
Problem: You are trying to add a custom link to the WPML language switcher in your theme's PHP file but are unsure where to insert the PHP code or how to make it work. Solution: We recommend using the icl_ls_languages hook to customize the WPML language switcher. You can add the following code in the
For more details, you can refer to our documentation on icl_ls_languages.
If this solution does not resolve your issue or seems outdated, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If needed, please open a new support ticket for further assistance.
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.
Background of the issue:
I am trying to add a custom link to the WPML language switcher for our Danish webshop: hidden link. At the request of your supporter, Marcel, I attempted to add PHP code to my theme's PHP file using the guide provided, but I am unable to find the correct place to insert the code or make it work. I am concerned about making changes to the theme's PHP file to avoid potential crashes.
Symptoms:
I can't find the right place to insert the PHP code or get it to work.
Questions:
How can I add a custom link to the WPML language switcher?
Where should I insert the PHP code in my theme's PHP file?
Thank you for contacting WPML Support. Sorry for the delay due to high workload and the reply time will be shorter from now. You may use icl_ls_languages hook to customize the built-in language switcher of WPML. Here is an example code, which you can add in functions.php file of your theme/child theme and it will add external link to WPML language switcher(screenshot attached):
function custom_language_switcher_links( $languages ) {
$languages['external1'] = array(
'url' => '<em><u>hidden link</u></em>', // Replace <em><u>hidden link</u></em> with your required external URL
'native_name' => 'International site',
'translated_name' => 'International site',
'country_flag_url' => '<em><u>hidden link</u></em>', // Replace it with flag URL
'language_code' => 'ext1',
'code' => 'ext1',
);
return $languages;
}
add_filter( 'icl_ls_languages', 'custom_language_switcher_links' );
Hi there. Thanks a lot for your help until now🙏. Close but not still there, I get these issues when I'm trying to add your code in my functions file.
Can you help me with why this is?
Thanks a lot for your try, but it still fails, but now only at our shop page: amladcykler.com/shop/. Try to take a look on my screenshot below. Really hope you can help🙏
Sorry for the trouble. I was testing earlier with the default WP theme which didn’t show any warnings. Now I tested using the Flatsome theme and was able to see the warnings. I’ve updated the code to fix this:
function custom_language_switcher_links( $languages ) {
$languages['ext1'] = array(
'url' => '<em><u>hidden link</u></em>', // Replace <em><u>hidden link</u></em> with your required external URL
'native_name' => 'International site',
'translated_name' => 'International site',
'country_flag_url' => '', // Replace it with flag URL
'language_code' => 'ext1',
'code' => 'ext1',
'active' => false,
);
return $languages;
}
add_filter( 'icl_ls_languages', 'custom_language_switcher_links' );
Here is an example page for your reference: hidden link
Please try this updated code and let me know how it goes. Thanks a lot for your cooperation and patience