Support » Plugin: Polylang » [Plugin: Polylang] Problems with pll_current_language

  • Resolved tiagobugarin

    (@tiagobugarin)


    The past few days i have been trying to implement a PHP code to a theme that should display different logos depending on the language. For this i choose the pll_current_language from Polylang API.
    This is how i am using it in the header.php:

    <?php
      if (pll_current_lang() === 'pt') {
        echo('/images/logo-pt.gif" width="508" height="145"');
      } elseif (pll_current_lang() === 'en') {
        echo('/images/logo-en.gif" width="508" height="145"');
      } elseif (pll_current_lang() === 'es') {
        echo('logo-es.gif" width="508" height="145"');
      } else {
        echo('/images/logo-pt.gif');
      }
    ?>

    With this on the index.html comes out completely empty. If i cut it, the html comes out as it should.

    Trying to get something more to understand what is happening i put a single line of PHP in the begining of the header.php so i could understand a bit more:

    <!DOCTYPE HTML>
    <!-- <?php pll_current_language(); ?> -->
    <html lang="pt">

    The result of this is:

    <!DOCTYPE HTML>
    <!--  -->
    <html lang=pt>

    My understanding from the documentation PDF is that i should get something like: <!-- en -->.

    I understand that i must be making some mistake but, even so, shouldn’t the PHP code fail at this point and go on with the rest of the thing?

    For better understanding i am linking here The Good header.php and The Bad header.php.

    http://wordpress.org/extend/plugins/polylang/

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter tiagobugarin

    (@tiagobugarin)

    Forgot to say that I have tried both 0.8.7 and development versions.

    Thread Starter tiagobugarin

    (@tiagobugarin)

    Made some progress. 🙂 but as can be seen in Still Bad One now I all the if and elseifs fails directly to the last resort else condition.

    Also tryed strcmp() but haven’t worked.

    Still looking out for a solution…

    Thread Starter tiagobugarin

    (@tiagobugarin)

    Well, I found a solution for my problem changing the way it worked.

    Instead of:

    <?php
      if ($pll_current_lang == 'pt') {
        echo('/images/logo-pt.gif" width="508" height="145"');
      } elseif ($pll_current_lang == 'en') {
        echo('/images/logo-en.gif" width="508" height="145"');
      } elseif ($pll_current_lang == 'es') {
        echo('/images/logo-es.gif" width="508" height="145"');
      } else {
        echo('/images/logo-unknown.gif" width="508" height="145"');
      }
    ?>

    I went:

    /images/logo-<?php echo pll_current_language(); ?>.gif"

    As i got it to work I will mark it as resolved but please I still would like to know what is wrong with the other method.

    Probably this comes a bit late. 🙂 But isn’t it just because it has to be pll_current_language() instead of pll_current_lang() (in your first example)?

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Polylang] Problems with pll_current_language’ is closed to new replies.