Saya menggunakan Plugin WPML untuk salah satu situs saya yang menampilkan tulisan dalam 2 bahasa atau multilanguage. Suatu ketika, saya perlu memeriksa kode bahasa yang sedang aktif supaya dapat mengeksekusi kode yang saya buat sendiri di sidebar yang terkait dengan bahasa yang sedang aktif. Pertanyaannya adalah: Bagaimana saya mendapatkan kode bahasa yang sedang aktif tersebut? Setelah mencari ke situs pembuat plugin ini, kemudian saya menemukan jawabannya melalui tulisan berikut WPML coding API. WPML ternyata telah menyediakan beberapa konstanta yang dapat digunakan untuk mengetahui: 1) Kode bahasa yang sedang aktif, 2) Nama bahasa asli yang sedang aktif, dan 3) Nama bahasa yang sedang aktif dalam bahasa Inggris. Terima kasih buat WPML karena sudah menyediakan konstanta ini!
Jika Anda ingin mengetahui nilai dari ketiga konstanta tersebut, maka Anda dapat meletakkan kode ini ke dalam file index.php pada theme yang Anda gunakan.
<?php echo "<br />Kode Bahasa: ".ICL_LANGUAGE_CODE; echo "<br />Nama Asli Bahasa: ".ICL_LANGUAGE_NAME; echo "<br />Nama Bahasa dalam bahasa Inggris: ".ICL_LANGUAGE_NAME_EN; ?>
Misalkan Anda menggunakan dua bahasa, yaitu: English (en) dan Bahasa Indonesia (id) untuk situs Anda. Lalu Anda ingin memeriksa hanya kode bahasa yang sedang aktif, sehingga Anda dapat mengeksekusi kode tertentu yang terkait dengan kode bahasa yang sedang aktif tadi, maka Anda bisa menggunakan kode ini:
<?php if (ICL_LANGUAGE_CODE == 'en') { // letakkan kode Anda di sini jika kode bahasa yang aktif adalah 'en' (English) } elseif (ICL_LANGUAGE_CODE == 'id') { // letakkan kode Anda di sini jika kode bahasa yang aktif adalah 'id' (Indonesian) } ?>
Semoga dapat membantu.

Really useful snippet of information. Thanks!
Thanks so much for the hint. Was looking for this constants.
Daniel
thanks! this just saved my life
@Philip Jones
Glad to know it useful for you.
@Daniel
You are very welcome!
@Fernanda Thiesen
Great! That’s why I share it.
thanks for your post and information
I need this tutorial a long time ago, This is clean and easy to use. Thanks for sharing your discover, Cheers!!!
I’m trying to do something like this. I’m not a programmer but I think there might be some syntax error… if you can please help me fix it
@Elisa
You should change that code become something like this:
Very useful, thank you!!!
Excellent. Thank you very much for taking the time to share with those who are starting on the subject. Greetings.
What an epic publish – in fact essential! A fantastic deal appreciated!
Thanks.
I am using the K2 theme with the WPML plug-in. I have renamed the blog tab to “Home” but when I view the site in French, I want the blog tab to say “Accueil”. I tried editing wp-compat.php to add the conditional logic below (two different versions), but neither version worked. Is it possible to conditionally display the K2 Blog tab in different languages? Why isn’t WPML picking this up as a translatable string?
if (ICL_LANGUAGE_CODE == ‘en’) {
echo ‘Home‘;
} elseif (ICL_LANGUAGE_CODE == ‘fr’) {
echo ‘Accueil‘;
}
Thanks for the hint.
I had to use it to set the language of the page because WPML wordpress plugin does not set this:
<html xmlns="http://www.w3.org/1999/xhtml" lang="”>
I’ve also struggled with wpml_get_current_language function, but ICL_LANGUAGE_CODE simply works.
Thanks for the useful information.
Regarding WPML, How can i get the Recent Posts in Specific Language?
Thanks
Excellent tip – much appreciated. Pity one couldn’t find this sort of stuff in the WPML help files. Anyhow, very grateful to find it here. Many thanks.
Thanks for the hint. I need this tutorial a long time ago. I’m trying to do something like this. Keep it up.
Thank you SO much! This saved my life!
Hey thanks a lot, for some reason I was putting $ in front of the constants, not very used to PHP I guess.
Any idea of how I could incorporate this into ‘the loop’ ? I got something like this:
$args = array(
‘meta_key’ => ‘sgt_slide’,
‘meta_value’ => ‘on’,
‘numberposts’ => -1,
);
$slides = get_posts($args);
“sgt_slide” is a custom attribute used on the theme, the problem right now is that is fetching all of the posts that have it, not just the ones in THAT specific language, there is nothing related to the language in the wp_meta key, so I’m not sure ‘the loop’ by itself could help me? I’d really like to get this working before spending $30 on the plugin, any help you could give me will be greatly appreciated.
Cheers,
Leo
Thanks for this tutorial. it is amazing how you can find an answer to all your questions here from the Internet. great and thanks again!
Thank u, just saved me