Home > WordPress > How to Get Current Language Code by Using WPML Plugin of WordPress

How to Get Current Language Code by Using WPML Plugin of WordPress

I have been using WPML Plugin for one of my multi language websites. Once upon a time, I needed to check the current language code in order to execute my own code that I wrote in the sidebar related to the current language. The question is: How did I get that current language code? After do some searching through the author’s website, then I found the answer from this following post: WPML coding API. WPML has provided the constants in order to get: 1) The current language code, 2) The name of current language in the original (current) language, and 3) The name of the current language name in English. Thanks to WPML for providing this constants!

If you wan to get the value of those three constants, then you can put this code to your index.php file of your current theme.

<?php 
  echo "<br />Language Code: ".ICL_LANGUAGE_CODE; 
  echo "<br />Original Language Name: ".ICL_LANGUAGE_NAME; 
  echo "<br />Language Name in English: ".ICL_LANGUAGE_NAME_EN; 
?>

Suppose you are using English (en) and Indonesian (id) language, and you want to check the current language code only, so you can execute the certain code related to the current language code, then you can use this following code:

<?php
  if (ICL_LANGUAGE_CODE == 'en') {
    // put your code here if the current language code is 'en' (English)
  } elseif (ICL_LANGUAGE_CODE == 'id') {
    // put your code here if the current language code is 'id' (Indonesian)
  }
?>

Hopefully this will be helpful.

  • Share/Bookmark
217 views Print This Post Print This Post