change header image based on language selected
-
On my site, the visitor has an option to select a language. Is it possible to have the header image change based on the language selected? I changed the text into French and Croatian so I have 3 header images in different language. I’d like to have the appropriate header image with each different language.
Thank you
-
Assuming you have a variable to store the chosen language (let’s call it
$myLangfor sake of argument) all you actually need to do is to create different header.php files, named with the language in them as follows:header-fr.phpandheader-co.php(Change the codes that I’ve used here for what you’re actually using, I’ve called Frenchfrand Croatianco).Now, in your site’s PHP file, wherever you see the code
get_header()change it toget_header($myLang)and there you go.Hope that helps
Peter
how does the get_header($myLang) know which language is being used?
Should there be some kind of if/else statement?test if the language changes with this:
<?php $mylocale1 = get_locale(); $mylocale2 = get_bloginfo('language'); $mylocale3 = $locale; // a WordPress Global variable echo $mylocale1; echo $mylocale2; echo $mylocale3; ?>keesiemeijer how will the header change with each different language?
Sorry, you said that you had the option to select a language, so I had assumed that you had implemented that yourself. Without being able to see your theme’s .php files, it’s impossible to know how the language choice is being selected and stored.
It does look like you’re using the QualiFire theme, perhaps you should go back to them and ask.
Sorry I can’t be more helpful.
Peter
Thanks, I’m using the qTranslate plugin. What file would I go in to see what/ how the language is being seledted?
Try it with something like this:
$mylocale = get_bloginfo('language'); if($mylocale == 'en-US') { // show English image } elseif($mylocale == 'fr-FR'){ // show French image } elseif($mylocale == 'hr-HR'){ // show Croatian image } else { // show default image }Hello all,
Not knowledgeable at all in PHP but have managed to find my way around wordpress and have it do what I wish it to do.
However, I have a problem:
I am using Qtranslate (for two languages). My navigation is stored in header.php and is in english at the moment. When I switch to the other language for a post for instance, I would like the navigation to be in the language of the post currently seen.
I assume I would have to call a different header to match the language selected!? It is probably quite straightforward (probably even basic) but I’m stuck.
Unfortunately, this probably requires me to create my own snippet of PHP and I am not capable of that yet… Hopefully soon…
Could you please either tell me what the optimum solution to my problem would be or just the bit of code I need to get this to work.
Thank you in advance for your help.
BDps: I have tried petervandoorn solution but i don’t know how to declare that $myLang variable. Yes, I”m that bad with php 🙁
i solved my problem by using network of sites and creating child theme for site in other language. thanks.
BDHi I need urgent help on this site: http://ipadangola.sycdn.us/
I need to switch the logo from English to Portuguese on language switching. please assist, also the icons would need to switch as well to Portuguese. i used this:<?php
$mylocale = get_bloginfo(‘language’);
if($mylocale == ‘en-US’) {
<img src=”<?php bloginfo(‘stylesheet_directory’); ?>/images/tagline.png” width=”398″ height=”15″>
}
elseif($mylocale == ‘pt-pt’){
<img src=”<?php bloginfo(‘stylesheet_directory’); ?>/images/tagline-por.png” width=”398″ height=”15″>
}
?>@hova
The link shows a blank page.Please refresh this link? http://ipadangola.sycdn.us/
Herewith the amended code, but the image I’m working on is now not showing.<?php
$mylocale = get_bloginfo(‘language’);
if($mylocale == ‘en’) {
?>
<img src=”<?php bloginfo(‘stylesheet_directory’); ?>/images/tagline.png” width=”398″ height=”15″>
<?php
}
elseif($mylocale == ‘pt-pt’){
<img src=”<?php bloginfo(‘stylesheet_directory’); ?>/images/tagline-por.png” width=”422″ height=”15″>
}
?>Try echoing $mylocale and see wat the value is:
$mylocale = get_bloginfo('language'); echo $mylocale;maybe it is pt_PT or pt-PT:
elseif($mylocale == 'pt-PT'){ // rest of code }Or just
<?php if(qtrans_getLanguage()=='en'): ?> <img src="loggo.jpg"/> <?php endif; ?> <?php if(qtrans_getLanguage()=='cr'): ?> <img src="loggocr.jpg"/> <?php endif; ?> <?php if(qtrans_getLanguage()=='fr'): ?> <img src="loggofr.jpg"/> <?php endif; ?>Assuming you’re using qtranslate
Am using WMPL. Thanks.
The topic ‘change header image based on language selected’ is closed to new replies.