Support » Plugin: Multisite Language Switcher » Display content based on current language with IF/ ELSE

  • Resolved dkps

    (@dkps)



    Hello,

    how can you display content based on the current language (on a bilingual website)?

    I put this code from http://msls.co/ in my child theme’s functions.php:

    function switcheroo() {
    $blog     = MslsBlogCollection::instance()->get_current_blog();
    $language = $blog->get_language();
    }

    And this in my footer.php:

    <?php
    if( switcheroo() == 'de_DE' ){ ?>
    <!-- German content here-->
    German content
    <?php
    }else { ?>
    <!-- English content here-->
    English content
    <?php }?>

    My ELSE rule works, but not the IF rule.
    I guess the solution must be really obvious, but I’m a PHP newb, so I just don’t see it.

    Any help is appreciated.

    Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Dennis Ploetner

    (@realloc)

    Your function does not return the $language.

    
    function switcheroo() {
        $blog = MslsBlogCollection::instance()->get_current_blog();
        return $blog->get_language();
    }

    You can also use the WordPress-function get_locale() in your case.

    <?php
    if ( 'de_DE' == get_locale() ) { ?>
    <!-- German content here-->
    German content
    <?php } else { ?>
    <!-- English content here-->
    English content
    <?php } ?>

    That’s a lot less complicated and it works for me!

    Thanks a lot and have a nice week!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display content based on current language with IF/ ELSE’ is closed to new replies.