Archived topic
logos in two languages with ploylang
20 replies · Started by John Dowling on October 8, 2018
Hi.
How can I have my logo change with the language?
I know this has come up before but I can't see what is the one best solution.
I'm using Generatepress Premium and polylang
Thanks, John
Hi John,
I feel like you already have but just to make sure, you've tried the solution here?
https://generatepress.com/forums/topic/change-logo-for-each-language-with-polylang/
Let me know :)
Unless I'm missing something Tom and the poster (Alexandre) went back and forth a few times with mixed results then Alexandre mentions that he got it working but doesn't say exactly how. Tom even asks him!
Not sure what he ended up doing.
I wonder if something like this would work?:
add_filter( 'generate_logo', function( $url ) {
if ( 'en_US' === get_locale() ) {
$url = 'https://example.com/logo.png';
}
if ( 'es_ES' === get_locale() ) {
$url = 'https://example.com/another-logo.png';
}
return $url;
} );
Of course, you'd need to change the values to check against.
I put that in GP hooks, Above header content. Checked "execute PHP". Doesn't seem to run the script.
http://www.smartersteps.ca/walk/
How to I activate the hook
Hi there,
filters should be added using one of the methods provided here:
Works like butter! Thanks
Glad we could be of help :)
A few moments later...
Just to add for anyone else finding this thread in the future, if you use the PHP snippet here.
<?php if ( get_bloginfo( 'language' ) == 'en-GB' ) { ?>
<img src="URL TO en_GB logo" />
<?php } elseif ( get_bloginfo( 'language' ) == 'fr-FR' ) { ?>
<img src="URL TO fr_FR logo" />
<?php } ?>
Then remove your default logo from the theme customizer it allows the PHP to load the correct logo for the language - rather than needing a browser cache clear/hard refresh for it to always show the correct version.
Cheers
Greg
Thanks for sharing that solution Greg!
I was able to get Tom's code working on my website (I also removed my logos from the customiser), however there is now no mobile logo as soon as the site goes to mobile view. How can I change that?
Greg's code didn't work for me by the way.
Many thanks in advance
That's odd, works perfectly for me on the latest GP - did you use absolute URLs for the logos in the PHP snippet?
I did use absolute URLs, correct. To go more into detail what your code does, it causes my website to go offline (critical bug in wordpress error). I implemented your code via functions.php and a child theme.
Maybe try implementing it with the Snippets plugin (this is how I have it setup rather than editing the functions.php file)
https://en-gb.wordpress.org/plugins/code-snippets/
Hi @scometames,
You may have to do the same thing to generate_mobile_header_logo filter do Tom did but for the mobile logo.
Example:
add_filter( 'generate_mobile_header_logo', function( $url ) {
if ( 'en_US' === get_locale() ) {
$url = 'https://example.com/logo.png';
}
if ( 'es_ES' === get_locale() ) {
$url = 'https://example.com/another-logo.png';
}
return $url;
} );