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 valuecountry_flag_url. So you should be able to get url by something like code below: