Skip Navigation

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

functions.php

file of your theme or child theme:

function custom_language_switcher_links( $languages ) {<br />    $languages['ext1'] = array(<br />        'url' => 'https://google.com/', // Replace https://google.com/ with your required external URL<br />        'native_name' => 'International site', <br />        'translated_name' => 'International site',<br />        'country_flag_url' => '', // Replace it with flag URL<br />        'language_code' => 'ext1',<br />        'code' => 'ext1',<br />        'active' => false,<br />    );<br />    return $languages;<br />}<br />add_filter( 'icl_ls_languages', 'custom_language_switcher_links' );

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.

This topic contains 5 replies, has 0 voices.

Last updated by Noman 1 month, 1 week ago.

Assisted by: Noman.

Author Posts
April 4, 2025 at 9:22 am #16896209

martinA-60

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?

April 6, 2025 at 9:19 am #16900979

Noman
WPML Supporter since 06/2016

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

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' );

You may customize it according to your needs.

Here is a doc for more details:
https://wpml.org/wpml-hook/icl_ls_languages/

Please let me know if this resolves the issue or if you need further assistance with this issue.

Thank you

external URL.jpg
April 9, 2025 at 7:51 am #16911734

martinA-60

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?

Skærmbillede 2025-04-09 kl. 09.50.29.png
April 9, 2025 at 10:19 am #16912547

Noman
WPML Supporter since 06/2016

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Could you please try to use the updated code and see if this resolves the issue:

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',
		'active' => 0,
    );
	
    return $languages;
}
add_filter( 'icl_ls_languages', 'custom_language_switcher_links' );

Please let me know the results,
Thank you

April 10, 2025 at 7:50 am #16916964

martinA-60

Hi there

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🙏

Skærmbillede 2025-04-10 kl. 09.40.12.png
April 10, 2025 at 12:29 pm #16918509

Noman
WPML Supporter since 06/2016

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

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