Archived topic
Site Logo & Title Links to Default Language in Second language Site
13 replies · Started by yitegele on December 27, 2022
Hi GP Team!
How are you?
I'm using Polylang as the multilingual plugin. My default language is English, and second language is Chinese.
After you click the Chinese flag and drump to Chinese site, if you click the site logo & title in header, it returns to English site, instead of Chinese site.
Besides, same problem is NOT happened in the footer's site logo & site.
Please help with it. Thank you so much!
Hi Yitegele,
Can you try adding this snippet?:
add_filter( 'generate_logo_href', 'tu_english_navigation_logo_url' );
function tu_english_navigation_logo_url( $url ) {
if ( ! function_exists( 'pll_current_language' ) ) {
return $url;
}
if ( 'Chinese' == pll_current_language( 'name' ) ) {
return 'URL/cn';
}
return $url;
}
Adding PHP: https://docs.generatepress.com/article/adding-php/#code-snippets
Replace Chinese with the Polylang language, and URL with the URL.
Let's tackle the footer link afterward. But, can you also try this first?: https://generatepress.com/forums/topic/polylang-navigation-logo-linking/#post-481658
Hi Fernando,
Thank you so much!
It is perfectly working with the site logo. Then the next step is the site title on the header, as the user from the above article only has the problem of site logo, but I both have site logo & title.
Thank you!
Try adding this as well:
add_filter( 'generate_site_title_href', 'tu_english_navigation_site_title_url' );
function tu_english_navigation_site_title_url( $url ) {
if ( ! function_exists( 'pll_current_language' ) ) {
return $url;
}
if ( 'Chinese' == pll_current_language( 'name' ) ) {
return 'URL/cn';
}
return $url;
}
Let us know how it goes.
Hi Fernando,
It is perfectly solved! Thank you so much!
You're welcome, Yitegele!
Hi GP team,
I'm having the same issue with a website in english and french.
The language plugin is Polylang.
The issue:
Site is in english by default. When I'm on the French version of the site and click on the header logo, it's always brings me back to the English version of the site.
I have tried the code snipped mentioned above by Fernando using the Code Snippets plugin.
But I can't seem to get it to work.
This is the snippet i used:
add_filter( 'generate_logo_href', 'tu_english_navigation_logo_url' );
function tu_english_navigation_logo_url( $url ) {
if ( ! function_exists( 'pll_current_language' ) ) {
return $url;
}
if ( 'french' == pll_current_language( 'name' ) ) {
return ' https://brigadeweb.com/fr ';
}
return $url;
}
Could you help me fix this?
Thank you!
Not sure if it's going to work, but can you try fr instead of french?
Hi Ying,
Unfortunately, it did not work.
How did you add the code?
Using the Code Snippets plugin.
Like this:
https://drive.google.com/file/d/1p2Jebxu58Heequ-aZJWu6-j5vxk0DqpE/view?usp=share_link
Try this code instead:
add_filter( 'generate_logo_href', 'fr_logo_href' );
function fr_logo_href( $url ) {
if ( function_exists( 'pll_current_language' ) ) {
$current_language = pll_current_language();
}
if ( 'fr' === $current_language ) {
$url= 'google.com';
}
return $url;
}
It works!
You are the best Ying. Thank you!
No problem :)