This site, WordPress project

This site is a full-fledged WordPress project in which I have applied my own solutions, the following can be noted from the serious improvements:

  • Support for Russian and English at the site and admin panel level, correct switching of localizations
  • Switching between two different WordPress schemes on the fly
  • Creating shortcodes
  • Refining the paid Wellow scheme
  • I talk about these developments in detail in the sections of the “Solutions” block on the sidebar of the site.

    Initially, this site was conceived as a small portfolio, which I sometimes used when looking for work. In order not to plagiarize, I created a simple scheme from scratch, you can still look at it, it is left as an example to demonstrate switching WordPress on the fly to different schemes. Then I had some small projects on foreign freelance and there was a need for an English-language copy of the portfolio. I decided not to make a second site and did not use any plugins for this purpose, I did it the simple way, combining the Russian and English versions in one place, enclosing them in shortcodes. At the very beginning, I switched languages ​​using cookies, but then I thought that the English version would not be indexed by search engines and began to look for a solution for transferring the language through the address bar. Several options were tried, at first I wanted to do it through web server redirects, connecting query vars, but after studying the forums I came to the conclusion that it is better to do this using WordPress, in the end I settled on using endpoints.

    Multilanguage support for WordPress



    This approach is used on this site, it is simple to implement but has some drawbacks and limitations.
    This is not a complete code, it’s just a decision of how you can enable multilingual support for WordPress.
    Given the texts of the programs involve maintaining two languages: English and Russian, languages can be more.

    Disadvantages:

    • Should always be a Russian and English version of the text in all places.
    • In the admin panel, the headers look unreadable.
    • You cannot use the following markup for categories and tags if they are direct output via function wp_list_ […], and the like.
    • When using additional text in your PHP code you should always call the function-translator.
    • Search engines will always receive text for the default language. I use my additional redirect plugin on my site when English is enabled, so search engines see both versions of the page.

    This approach is very simplistic and good for simple sites.

    Use in posts and pages:

    • [ru]Русский текст[/ru]
    • [en]English text[/en]

    Use in PHP code:

    
    <?php 
    //-- echo --
    stringTranslate('[en]English text[/en][ru]Русский текст[/ru]'); 
    //-- value --
    $text = stringTranslate('[en]English text[/en][ru]Русский текст[/ru]', false); 
    ?>
    
    

    Implementation:

    common.js (file javascript with your code):

    
    function changeLanguage(ob) {
      if (ob == "ru") {
        if (!confirm("Please, confirm changing language interface to English.")) {
          return;
        }
        document.cookie = "lang=en";
      }
      else {
        if (!confirm("Подтвердите, пожалуйста, смену языка интерфейса на Русский.")) {
          return;
        }
        document.cookie = "lang=ru";
      }
      location.reload();
    }
    
    

    On my website I use the simple Wodpress theme, i.e. there are no templates, additional files, etc. So here is an example only for the main schema file. This block displays two icons to switch languages, similar to those you can see on this website. The example of using the data display function in the code above.

    index.php:

    
    //.... HTML markup before
    <img src="<?php bloginfo('template_url'); ?>/images/en.png" 
      <?php echo (($lang == "en")?("title='English language is setting now.'"):
      ("style='opacity: 0.2; cursor: pointer;' onclick='changeLanguage(\"ru\");' 
      title='Set English as interface language.'")); ?>/>
    <img src="<?php bloginfo('template_url'); ?>/images/ru.png" 
      <?php echo (($lang == "ru")?("title='Русский язык интерфейса сейчас установлен.'"):
      ("style='opacity: 0.2; cursor: pointer;' onclick='changeLanguage(\"en\");' 
      title='Установить русский язык интерфейса.'")); ?>/>
    // HTML markup after ...
    
    

    functions.php:

    
    add_filter( 'the_content', 'content_translate' );
    
    function content_translate ($content) {
      return stringTranslate($content, false);
    }
    
    function stringTranslate($str, $isEcho = true) {
      $rez = $str;
      if ($_COOKIE['lang']) {
        $lang = $_COOKIE['lang'];
      }
      else {
        $lang = 'en';
      }
      $rStr = 'ru';
      if ($lang == 'ru') {
        $rStr = 'en';
      }
      $am = 0;
      while (true) {
        $pos1 = strpos($rez,"[".$rStr."]");
        if ($pos1 === false) {
          break;
        }
        $pos2 = strpos($rez,"[/".$rStr."]");
        if ($pos2 === false) {
          $pos2 = strpos($rez,"[".$lang."]",$pos1);
          if (!$pos2) {
            $pos2 = strlen($rez);
          }
        }
        else {
          $pos2 += strlen("{/".$rStr."}");
        }
        $rez = str_replace(substr($rez, $pos1, $pos2 - $pos1), "", $rez);
        //-- decline endless cycle --
        $am++;
        if ($am > 100) {
          return "Cycle error!";
        }
      }
      if ($isEcho) {
        echo str_replace('[/'.$lang.']', "", str_replace('['.$lang.']', "", $rez));  
      }
      else {
        return str_replace('[/'.$lang.']', "", str_replace('['.$lang.']', "", $rez));      
      }
    }
    
    

    That’s all, I wish you all good luck.