It’s silly to have dropdown when you have only two languages. Makes sense if there are more. I want to have just a simple button that will switch to the other language and I can’t find any guide on google.
It’s silly to have dropdown when you have only two languages. Makes sense if there are more. I want to have just a simple button that will switch to the other language and I can’t find any guide on google.
2
Answers
You need to create a custom language switcher.
The first step is to add the PHP code responsible for rendering the language switcher on your page. For that, you create a function that adds a div container with the language switcher inside it. We can use the wpml_add_language_selector action to render the language switcher.
In this example, we want the new language switcher to be displayed in the footer, so we use our new function with the WordPress’s own wp_footer hook.
The complete PHP code will look like this.
You can copy and add it to your (child) theme’s functions.php file.
With the previous code in place, we already have a new language switcher added to the footer of our website. Now, it’s time to customize it so that it is floating in the bottom right corner of the website. You can do this using the position: fixed CSS attribute.
Use the following steps to add the CSS code:
Alternatively, you can add this CSS code by going to Appearance → Customize and clicking Additional CSS.
The following example adds some extra customization like rounded borders and box-shadow. Of course, you can customize it as you want.
Finally, you need to adjust some settings so the language switcher displays only the flags.
Use the following steps:
You can find the complete documentation at WPML webiste.
I add the css here to include the | "Pipe" between two languages in the switcher