Multilingual site branding with Polylang

Hi there,

I’d like to broadcast different site branding for each language mode using Polylang.
For now, I’ve tried two methods as described below but neither of them worked:

  1. Putting the following code in a file called ‘wpml-config.xml’ under ‘wp-content/polylang’ directory:

After doing so, I went to Settings -> Languages -> Strings translations but nothing happened.

  1. Putting the following code in the end of the header.php file under ‘astrid-child’ folder:
    <?php
    if (ICL_LANGUAGE_CODE == 'zh') { // 
    $logo='<img src="uploads/2018/11/title_張宇安_white.png">';
    } else if (ICL_LANGUAGE_CODE == 'en') { // English
    $logo='<img src="uploads/2018/11/title_yuanchang2_white2.png">';
    }
    echo $logo;
    ?>	

The appearance of my site didn’t change at all after doing this.

There must be some mistakes but I couldn’t find out.
Id’ really appreciate it if anyone could help. many thanks!

Hello there,

Try the below function:

    add_filter( 'get_custom_logo', 'astrid_child_custom_logo' );
    function astrid_child_custom_logo() {
        $custom_logo_id = get_theme_mod( 'custom_logo' );

        // Default logo
        $image = wp_get_attachment_image( $custom_logo_id, 'full', false, array('class' => 'custom-logo'));

        // logo for en
        if( 'id' == pll_current_language() ) {
          $image_url = 'http://athemes.test/astrid/wp-content/uploads/sites/27/2016/02/s2.jpg';
          $image = '<img src="'.$image_url.'" class="custom-logo"/>';
        }

        // Logo for zh
        if( 'zh' == pll_current_language() ) {
          $image_url = 'http://athemes.test/astrid/wp-content/uploads/sites/27/2016/02/c1.png';
          $image = '<img src="'.$image_url.'" class="custom-logo"/>';
        }


        $html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
                esc_url( home_url( '/' ) ), $image);

        return $html;
    }

Add it to your child theme’s functions.php file.

Regards,
Kharis

Hello kharisblank,

Thanks for your reply.
I’ve modified the url for logos and put the code in my child theme’s functions.php file as below:

add_filter( 'get_custom_logo', 'astrid_child_custom_logo' );
function astrid_child_custom_logo() {
    $custom_logo_id = get_theme_mod( 'custom_logo' );

    // Default logo
    $image = wp_get_attachment_image( $custom_logo_id, 'full', false, array('class' => 'custom-logo'));

    // logo for en
    if( 'id' == pll_current_language() ) {
      $image_url = 'https://changyuan.com.tw/wp-content/uploads/2018/11/title_yuanchang2_white2.png';
      $image = '<img src="'.$image_url.'" class="custom-logo"/>';
    }

    // Logo for zh
    if( 'zh' == pll_current_language() ) {
      $image_url = 'https://changyuan.com.tw/wp-content/uploads/2018/11/title_張宇安_white.png';
      $image = '<img src="'.$image_url.'" class="custom-logo"/>';
    }


    $html = sprintf( '<a href="%1$s" class="custom-logo-link" rel="home" itemprop="url">%2$s</a>',
            esc_url( home_url( '/' ) ), $image);

    return $html;
}

However, the site branding does not change as I switch the language mode.
Did I miss any steps?

Thanks,
Kai

Hello Kai,

Try replacing this line:

if( 'id' == pll_current_language() ) {

to

if( 'en' == pll_current_language() ) {

the language code should be matched with one of registered languages in the Settings > Languages.

Regards,
Kharis

Yay it went out very well.
Thank you very much Kharis!! :slight_smile:

You’re welcome!

Please let us know in a new topic if you have any further questions, or if we can provide you with any other assistance.

Regards,
Kharis