Load different homepage based on WPML language

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' );

Bill Erickson

Bill Erickson is the co-founder and lead developer at CultivateWP, a WordPress agency focusing on high performance sites for web publishers.

About Me
Ready to upgrade your website?

I build custom WordPress websites that look great and are easy to manage.

Let's Talk