faced such a problem. On my landing page I implemented multilingualism on WordPress. I want to highlight the active language if its version is now selected. That is, if now www.site.ru/en - the en language was highlighted (that is, the active class was added to it). I tried using js, but nothing intelligible happened. Also tried using PHP,

<?php get_field('language') == 'ru' ? 'languague__link-active' : '' ?> 

This code is inserted into the class attribute, but it does not want to work. Tell me how can I solve this problem?

  • Would you even add what kind of addon you use, maybe there is something in its settings - DaemonHK
  • I don’t use any addon, I have a clean WordPress :) - Daniil Lav
  • your approach is generally correct, just check what is stored in get_field('language') - DaemonHK

1 answer 1

Parse javascript url page. Depending on the result, add a class to the desired element. On pseudocode:

 if (урл документа содержит /%язык%) { switch(/%язык%) case '/en': элементу с /en добавить класс active; case '/ru': элементу с /ru добавить класс active; case '/sw': элементу с /sw добавить класс active; } 

hang it on the onLoad page or at least a container with active languages.

But isn't the language in the page meta tags indicated?

  • Here everything is taken from index.php, that is, the language will not be parsed from meta tags. And you can write the code in more detail, I just didn’t quite understand what was written above. Active class: languague__link-active Languages: RU, UA, EN Thank you very much in advance! - Daniil Lav