Fail to Detect Current Language in function.php
-
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 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
The topic ‘Fail to Detect Current Language in function.php’ is closed to new replies.