[Resolved] Is there some language switcher code we can add to the header
This thread is resolved. Here is a description of the problem and solution.
Problem: The client needed to add a language switcher to the header container without placing it in a menu, as the page in question was a standalone landing page with no navigation to other pages. Solution: We recommended the following steps to add a custom language switcher: 1. If the theme allows adding content or code to the desired position, use the following PHP code to display a custom language switcher:
do_action('wpml_add_language_selector');
2. Alternatively, use the following shortcode to add a language switcher:
Please note that the solution provided might be outdated or not applicable to your case. If the issue persists, we highly recommend checking the related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need help, please open a new support ticket.
This is the technical support forum for WPML - the multilingual WordPress plugin.
Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.
I'm thinking it isn't necessary to have the language switcher in a menu as this page is essential a landing page and there are no other pages to navigate to. So is there some language switcher code we can add to the header container?
Thank you for contacting WPML Support. If your theme provides you the option to add content (for example a widget) or some code exactly on the position where you want to display the language switcher, please try the below steps:
1. You can use the below code in PHP files to show a custom language switcher on a specific position:
do_action('wpml_add_language_selector');
2. Or you can use the below shortcode:
[wpml_language_selector_widget]
And customize it from WPML >> Languages > Custom language switchers as you can see in the attached screenshot.
3. If the issue persists, please provide temporary access (WP-Admin and FTP Login info) to your site (preferably staging site), so that I can look into your setup and debug the issue.
Your next answer will be private which means only you and I have access to it.
=== Please backup your database and website ===
✙ I would additionally need your permission to deactivate and reactivate Plugins and the Theme and to change configurations on the site. This is also a reason the backup is really important.
Please let me know if this resolves your issue or if you need further assistance with this issue.
I don't think tis is possible with a shortcode as im struggling to find how to edit the header.
Your colleague helped me out with something similar a while back on another site. He added some custom code to the header. i tried copy this across but it didn't work. Please see the code in the screen of how it was used. The code is also below.
I’ll try my best to help you in this case, Can you please let me know a bit more details to better understand the issue:
1. In which place in your site header you want to display the language switcher?
2. Do you want to keep the same language switcher style as you have currently on your site as you can see in the attached screenshot?
3. At the moment, in mobile view, the language switcher shows by clicking the hamburger menu, is that fine or you want to display language switcher without clicking it as in the desktop view?
Thanks for the additional details. Yes, please provide temporary access (WP-Admin and FTP Login info) to your site (preferably staging site), so that I can look into your setup and debug the issue.
Your next answer will be private which means only you and I have access to it.
Thanks for sharing the login details. I’ve copied the desktop CSS in WPML >> Languages > Additional CSS section and removed the media query part so that it will not change the layout on mobile view. Now it should display like the desktop view. Could you please take a look and confirm if it's working?
Thanks for making the change. This is looking great. The only issue i have is that when on mobile I cannot select the other language in the drop down menu. When you tap the flag it just loads the same page. Please try changing the language yourself on mobile to see the issue.
I’ve updated the CSS and now it works correctly for me on mobile as you can see in the attached screenshots. Could you please try to clear your browser cache and take another look at it and let me know if this resolves the issue.
Please understand that I'm helping you here with an issue that is out of the scope of our support forum and we will not be able to support this particular fix in the future. Because the theme or our code might have changed, so please always be aware of this. Right now it's working without any issue.
Many thanks for your help! All is working fine on both desktop and mobile.
Much appreciated!
Thanks
Jack
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.