Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
The client wanted to add a separator like "|" between the languages in the WPML language switcher and needed help with the CSS code to properly position and style the separator. Additionally, the client required assistance with displaying the language switcher horizontally with the separator on mobile devices.

Solution:
We recommended checking our documentation on creating a custom language switcher and fixing styling issues:

To change the separator color and position, we provided the following CSS code:

.menu-item.wpml-ls-item.menu-item-wpml-ls-2-es::after {<br />    content: "|";<br />    position: absolute;<br />    right: 0 !important;<br />    top: 0px !important;<br />    color: red !important;<br />    left: 0 !important;<br />    margin-left: 19px !important;<br />}

For mobile alignment and separator, we suggested this CSS:

#et_mobile_nav_menu .menu-item.wpml-ls-item.menu-item-wpml-ls-2-es::after {<br />    content: "|";<br />    position: absolute;<br />    color: red !important;<br />    left: 20px !important;<br />    margin-left: 35px !important;<br />    bottom: 27px;<br />}

To ensure both languages appear on the same line on mobile, we provided additional CSS:

#et_mobile_nav_menu li#menu-item-wpml-ls-2-es, #et_mobile_nav_menu li#menu-item-wpml-ls-2-en {<br />    width: 50px !important;<br />    float: left !important;<br />}<br /><br />#et_mobile_nav_menu li.wpml-ls-item a {<br />    padding-left: 28.078px !important;<br />}

Please note that the solution provided might be outdated or not applicable to your case. If the issue persists, we highly recommend checking related known issues, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If necessary, please open a new support ticket for further assistance.

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.

Tagged: 

This topic contains 8 replies, has 3 voices.

Last updated by Mario 3 years, 1 month ago.

Assisted by: Mihai Apetrei.

Author Posts
December 5, 2021 at 5:32 pm #10129435

Mario

Hello, I want to add a separator like "|" in the language switcher like this: EN | ES. I've tried some os the codes found in this support forum but none has worked.

I'm using the Divi Theme. Please, could you help me?

Thanks in advance.
Mario

December 5, 2021 at 6:24 pm #10129501

Itamar
Supporter

Languages: English (English ) Hebrew (עברית )

Timezone: Asia/Jerusalem (GMT+02:00)

Hi, Mario.

Before your ticket is assigned to one of my colleagues, please allow me to walk you through some initial debugging steps. This will help speed up the support process.

Please see our guides on adding a custom Language Switcher at the following links to see if they help you achieve what you need.

https://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/

https://wpml.org/documentation/getting-started-guide/language-setup/language-switcher-options/how-to-fix-styling-and-css-issues-for-the-language-switchers/

I have also found the following simple CSS directive that you can tweak to your needs and add in WPML -> Language Switcher Options -> Additional CSS.

https://stackoverflow.com/questions/9171699/add-a-pipe-separator-after-items-in-an-unordered-list-unless-that-item-is-the-la/16131865

Regards,
Itamar.

December 5, 2021 at 10:33 pm #10129909

Mario

Hi Itamar,

Thanks for your help. I did more research and I've added this CSS code.
But... (see image attcahed).
1. How can I change the position o f the separator to be more centered?
2. How can I change the separator color?

.menu-item.wpml-ls-item.menu-item-wpml-ls-2-es::after {
    content: "|";
    position: absolute !important;
    right: 0 !important;
    top: 0px !important;
}
language.jpg
December 6, 2021 at 12:48 am #10129989

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Hi there.

To change it's color, you can use the "color:" attribute like this (check the latest line):

.menu-item.wpml-ls-item.menu-item-wpml-ls-2-es::after {
    content: "|";
    position: absolute !important;
    right: 0 !important;
    top: 0px !important;
    color: red !important;
}

To leave more spacing in front of the bar or after, you can use the "margin" property, but only after you also set the "left" property, because for the moment you have only the "right" property set and having the "left" one is also needed if you are using an absolute-positioned element like this where you want the margin to be taken into consideration.

So your new code that also contains color and the alignment for the languages separator will look something like this:


.menu-item.wpml-ls-item.menu-item-wpml-ls-2-es::after {
    content: "|";
    position: absolute;
    right: 0 !important;
    top: -1px !important;
    color: red !important; /* here we have the color */
    left: 0 !important; /* here we have the left property */
    margin-left: 19px !important; /* here we have the margin - you can use also margin-right, or both, if you want to have space in front and after */
}

Hope that makes sense.

Kind regards,
Mihai Apetrei

December 6, 2021 at 10:00 am #10132159

Mario

Hi Mihai, it works! One more question. On mobile the language switcher looks like this, see the image attached.
Is it possible to show it horizontally aligned and with the separator?
Thanks in advance.

mobile.jpg
December 6, 2021 at 6:00 pm #10135371

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Hi there.

For mobile, you should be able to use this other one instead:

#et_mobile_nav_menu .menu-item.wpml-ls-item.menu-item-wpml-ls-2-es::after {
    content: "|";
    position: absolute;
    color: red !important;
    left: 20px !important;
    margin-left: 35px !important;
    bottom: 27px;
}

For having both languages on the same line, I am not able to help because I can see only one language (ES) - I don't see the other one because you set it as hidden (attaching screenshot of what I see).

Screenshot 2021-12-06 at 7.58.43 PM.png
December 7, 2021 at 6:59 pm #10142075

Mario

Hi Mihai, I've activated the EN language. Please, could you check now?

Thanks

December 8, 2021 at 9:53 am #10145521

Mihai Apetrei
Supporter

Languages: English (English )

Timezone: Europe/Bucharest (GMT+02:00)

Hi there.

Please add the following parts of code under teh code you have already:

#et_mobile_nav_menu li#menu-item-wpml-ls-2-es, #et_mobile_nav_menu li#menu-item-wpml-ls-2-en {
    width: 50px !important;
    float: left !important;
}

#et_mobile_nav_menu li.wpml-ls-item a {
    padding-left: 28.078px !important;
}

That should do the trick.

Have an amazing rest of the day

Mihai