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 a freelance WordPress developer and a contributing developer to the Genesis framework. For the past 14 years he has worked with attorneys, publishers, corporations, and non-profits, building custom websites tailored to their needs and goals.

Ready to upgrade your website?

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

Let's Talk