Title: Fail to Detect Current Language in function.php
Last modified: August 31, 2016

---

# Fail to Detect Current Language in function.php

 *  [justkiddi](https://wordpress.org/support/users/justkiddi/)
 * (@justkiddi)
 * [9 years, 11 months ago](https://wordpress.org/support/topic/fail-to-detect-current-language-in-functionphp/)
 * Hi,
 * I am trying to write a function that requires knowing the current page’s language
   option. I have done many research and have tried the following functions:
    **
   get_locale()** – This function always return the default language rather than
   the language of the current page. **get_bloginfo(‘language’)** – Same outcome
   as the get_locale() function. **pll_current_language()** – Returns an empty string
   regardless of what $value I put (some people mentioned it’s returning a boolean
   false but I am not sure if that’s the case for me).
 * Here is my [site](http://justkiddi.com) and the code I’m trying to implement:
 *     ```
       function wc_add_to_cart_message_filter($message, $product_id = null) {
           $currentlang = get_bloginfo('language'); //also tried the two methods mentioned above
           if($currentlang=="en_US"){
               $message = 'en_US';
           }
           elseif($currentlang=="zh_TW"){
               $message = 'zh_TW';
           }
           elseif($currentlang=="zh_CN"){
               $message = 'zh_CN'
           }
           else{
           $message = 'null';
           }
           return $message;
       }
       ```
   
 * Really simple function, but just couldn’t get the correct $currentlang value.
   Any suggestion is greatly appreciated. Thanks in advance!
 * Allen
 * [https://wordpress.org/plugins/polylang/](https://wordpress.org/plugins/polylang/)

The topic ‘Fail to Detect Current Language in function.php’ is closed to new replies.

 * ![](https://ps.w.org/polylang/assets/icon-256x256.png?rev=3433336)
 * [Polylang](https://wordpress.org/plugins/polylang/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/polylang/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/polylang/)
 * [Active Topics](https://wordpress.org/support/plugin/polylang/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/polylang/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/polylang/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [justkiddi](https://wordpress.org/support/users/justkiddi/)
 * Last activity: [9 years, 11 months ago](https://wordpress.org/support/topic/fail-to-detect-current-language-in-functionphp/)
 * Status: not resolved