Site logo

Archived topic

Conditional Logo URL Help

7 replies · Started by Melvin on August 25, 2022

Viewing posts 1–8 of 8

Hi,

Let's say I have two Primary menus. One is “English” and the other is “Chinese”.

Currently, I'm using the Conditional Menu plugin to show the menu depending on the pages that are active. But it doesn't have conditional logo settings.

How do I change the logo URL based on the menu selected?

I want the logo to link to the “English” Homepage (which is currently the default) and the logo to link to the Chinese Menu homepage when “Chinese” is selected.

I hope I didn't confuse you with my question. 😅

Hi there,

can you share a link to the site where i can see the different menus ? I can then look to see how we swap logos based on that change

Hi, David,

Please go to this site. When you click on the logo, it brings you to the default English menu homepage. Now, click on the last link that shows some Chinese characters. You'll see a page with all the menu links in Chinese characters. Clicking on the logo will bring you back to the English menu home page. I want the logo URL when I'm on the Chinese menu to bring me back to the Chinese menu instead of the English one.

Thanks. 😊

Hi Melvin,

This filter should work on a Chinese language page.
But I checked your site, the pages that are supposed to be Chinese are still in English.
https://www.screencast.com/t/xObTaE7aFu

add_filter( 'generate_logo_href', function() {
   if (get_bloginfo("language") === 'zh-CN') {
      return "https://NEW-URL-HERE";
   }
      return home_url( '/' ) ;
} );

Hi, Ying.

Thanks for the quick response.

Sorry for the noob question. How do I change the <html lang="en-US"> to <html lang="zh-CN">? Do I simply change the texts in the page to Chinese?

Usually, when people have more than one language on their sites, they would use a plugin like Polylang to handle it.

But if you don't think that's necessary, we can modify the code so it uses page id as the condition, for example:

add_filter( 'generate_logo_href', function() {
 if (is_page( array( 3, 81, 6 ) ) ) {
    return "https://NEW-URL-HERE";
} 
	return home_url( '/' ) ;
} );

You can replace the 3, 81, 6 with your page ids, you can get the ID in the page editor's URL.

Hi, Ying.

It works! Thank you so much! I appreciate you.

Best regards,
Melvin Neo

You are welcome Melvin :)

This archived topic is closed to new replies.