Ecommerce Shopify WordPress Discussion

How to get the Custom flag for a Language using Language Code in WPML

I am using WPML for multilingual functionality. I want to display the Language Name and Language Flag based on the Language code. I can get the Language Name using the below filter. Here I have used 'de' as an example. This can be any other Language code. $lang_code = 'de'; $lang_name = apply_filters('wpml_translated_language_name', false, $lang_code ); However, I am not able to retrieve the Flag associated with that language. I found an option to get the Flag using the below code but the issue is that it doesn't work if Custom Flag is configured for the language in the backend. $flag_url = ICL_PLUGIN_URL . '/res/flags/' . $lang_code . '.svg'; I more thing is I don't want to use any hooks which loops through all the available languages to get the flag for 1 language as it is not the efficient way. Thanks in advance.
There is hook called wpml_active_languages, whose returned array includes for every language value country_flag_url. So you should be able to get url by something like code below: $languages = apply_filters( 'wpml_active_languages', NULL, 'orderby=id&order=desc' ); $lang_code = 'de'; if (isset($languages[$lang_code]) && isset($languages[$lang_code]['country_flag_url'])) { $country_flag_url = $languages[$lang_code]['country_flag_url']; echo $country_flag_url; }

February 13, 2024

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.