WPML - How to keep the language when clicking on logo to go back to homepage?

Hallo,

I created a bilingual website for a customer with WPML and have an unsolved problem… I don’t know how to stay with the selected language when I click on the logo in the header.

My idea was to create a second header and set one link of the logo in German and one in English. But unfortunately I haven’t found a way to select the header for the pages wich are created with WPML…

So my question: Is there a way to stay with the selected language when i click on the Logo in my header?

Thx, Pascal

Hi Pascal,

This is possible with customization. Setup a child theme and check this customization best practices. The file responsible for logo link is _brand.php from this folder: \wp-content\themes\x\framework\legacy\cranium\headers\views\global. Copy that file on the same file folder on your child theme here: \wp-content\themes\x-child\framework\legacy\cranium\headers\views\global. Create the folder if it doesn’t exist on your child theme folder. Replace the href value with the selected language URL. See this guide: https://wpml.org/wpml-hook/wpml_home_url/

Hope this helps.

Hi,

I followed your instructions, but i can’t see a difference…

Can you see the fault in the updatet _brand.php? Do I need to delete something?

Hi Pascal,

I am sorry for the confusion. I assume you are using legacy header and not Pro header. That code and customization will work on Legacy header only. Now when using Pro header, like with what I’ve seen on your current setup, we can just set image link URL. How it works, the links and images will depend on what we add on the header builder. Although, we do have existing issues with the PRO header builder and WPML. Please check the article.

Hi Lely. Ok i hope there will be a solution soon, so that my customer is happy.

Hi There,

Our developers are working on it, unfortunely we cannot provide an ETA for the solution.

Thanks for understading.

Hi, pascalmainz!

In the meantime you can use some jQuery code I’ve put together to change the url.

First, set up a custom id for the image in a header (CUSTOMIZE button) with something like customlogo.

Then, switch to JS in header and use this:

jQuery(document).ready(function () { if(window.location.href.indexOf("/en/") > -1) { jQuery("#customlogo").attr("href", "/en/"); } });

I’m using link based language setup - checking for /en/
Logo link is also relative as I’m soon changing the website url, you can use https://site.com/en/

Thanks for sharing the solution with community members @kolyasapphire. :slight_smile:

No problem! Glad to help. Would be great to have a forum category for user-contributed code snippets like these :slight_smile:

Yeah, it is a very good idea.
I will relay your message to the person in charge with our community.

Thanks.

Thanks kolyasapphire for working on a solution. Unfortenetly i’m not the best when it comes to code :sweat_smile:
Is it possible to send a little step by step workthrough?

Hi @pascalmainz,

Since your theme is on Pro, then please do this.

  1. Edit your header and inspect your image (the logo)
  2. Then add customlogo in that image’s ID field

  1. Next is adding the code to your header custom javascript section.

Hope this helps :slight_smile:

It’s still the same issue… Do i miss something here?!

Hello There,

You have a different set up. Please update the JS code and use this instead:

jQuery(document).ready(function () {
    if(window.location.href.indexOf("/de/") > -1) {
       jQuery("#customlogo").attr("href", "/de/");
    }
});

Hope this helps. Kindly let us know.

Wohoo! It works like magic :grinning:
Thank you guys for solving this issue (Special thanks to kolyasapphire!!!)

Don’t mention it.
If you need anything else we can help you with, don’t hesitate to open another thread.

No problem!