I have a multilingual site and I have used WPML for this purpose. How can I use two different footers when changing the language? The footers are not designed with widgets and are separate pages.
WPML has it's own language code variable, ICL_LANGUAGE_CODE
... so what you have to do is check that variable for the language you're looking for/want to work with.
WordPress allows you to have multiple footers, you can start by duplicating the theme's footer.php
file and appending something to the name, like footer-english.php
then make the necessary changes in that file.
Then you run a conditional check on the WPML language variable, and if it's a match (==
) to a language code, then you get the footer you want using get_footer();
.
if( ICL_LANGUAGE_CODE == 'en' ):
get_footer( 'english' ); //will get file footer-english.php
elseif( ICL_LANGUAGE_CODE == 'fr' ):
get_footer( 'french' ); //will get file footer-french.php
endif;
The other way to go about achieving a similar result would be to take the single footer.php
file and using the ICL_LANGUAGE_CODE
variable and conditional if
checks and just outputting different content within the file based on the language. I'd only recommend this approach if you have pre-set number of languages and know that you won't be adding any others in the future. You could do something like this:
if( ICL_LANGUAGE_CODE=='en' ):
echo '<div class"site-info">English Site Name</div>';
elseif( ICL_LANGUAGE_CODE=='fr' ):
echo '<div class"site-info">Nom de site francais</div>';
endif;
I don't believe that'd be as efficient as just running the conditional check once and loading the appropriate footer.php file, but it's always nice to have options.