WPML Change order of menu languages in dropdown
- January 17, 2024
- -
- Javascript Programming Wordpress WPML
- -
- nicolas
Hello.
With the following javascript code you can change position in languages. Something wpml doesn't support so far.
The example is for two languages but you can extend the code for more.
If you need help ask me.
var grlang = document.querySelectorAll("a[title='GR']")[0]; var grhref = grlang.attributes[1].value; var enlang = document.querySelectorAll("a[title='EN']")[0]; var enhref = enlang.attributes[1].value; grlang.attributes[0].value = 'EN'; //main language title grlang.childNodes[0].innerText = 'EN'; //main language title grlang.attributes[1].value = enhref; //main language redirect value enlang.attributes[0].value = 'GR'; //second language title (after hover of dropdown) enlang.childNodes[0].innerText = 'GR'; //second language title enlang.attributes[1].value = grhref; //second language redirect value
Before you try the script, make sure that the name of the languages is correct by inspecting the source code of the element (right click in your browser and select inspect)
This post is also available in: Ελληνικά