It is necessary when the user logs on to the site to determine the language version of the site on his browser. All this should be implemented on CMS WordPress. I found such code, but I have no idea how and where to insert it.

 // action on checking the language and setting the language cookie is carried out only on the index.php page
 if (strpos ($ _ SERVER ["REQUEST_URI"], "/index.php") or (substr ($ _ SERVER ["REQUEST_URI"], -1) == "/")) {

 // if the input is made without specifying the language
 if (! $ _ GET ['lang']) {

     // we check, the language can be specified in cookies, if not, then we look at the browser localization
     if (! $ _ COOKIE ['lang']) {

         $ b_lang = explode (",", $ _SERVER ["HTTP_ACCEPT_LANGUAGE"]);

         // if localization is Russian or Ukrainian or Belarusian, then we believe that the user needs to give the Russian version of the site.
         if (($ b_lang [0] == "ru") or ($ b_lang [0] == "be") or ($ b_lang [0] == "ru-UA") $ lang = "rus";

         // for all other localizations, give the English version
         else $ lang = "eng";

     }

     // if the language is already specified in the cookies, then use it in the system
     else $ lang = $ _COOKIE ['lang'];
 }

 // if the page is requested with the language specified, then this language is used in the system, and we remember it in the cookie
 else {
     $ lang = $ _GET ['lang'];
     setcookie ("lang", $ lang, time () + 30758400, "/");
 }

 }

    1 answer 1

    From the commentary it is obvious that you need to paste this code into index.php .

    • The fact is that even if this code performs the function of determining the user's language, but there is no instruction for explanations, so that having entered the site a person would see the appropriate language version of the site. - Maxim Zagumennyy
    • Did you try to insert it at least? He works? - Andrewus