When using WPML for a multi-lingual website, you may need to load specific items based on the current language. Use the ICL_LANGUAGE_CODE
constant to determine the current language.
In the code below, I’m loading a different homepage file (home-cn.php) if the current language is Chinese.
/**
* Load different homepage based on WPML language
* @author Bill Erickson
* @link https://www.billerickson.net/code/load-different-template-based-on-language
*
* @param string $template
* @return string
*/
function be_template_based_on_wpml( $template ) {
if( is_home() && ICL_LANGUAGE_CODE == 'cn' )
$template = get_query_template( 'home-cn' );
return $template;
}
add_filter( 'template_include', 'be_template_based_on_wpml' );