WordPress Change logo image when I click to a different language

后端 未结 6 941
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 19:59

I have a multilingual website. Is there a way I can change the logo.png to a different .png after I switch to \"India\"? I am using polylang plugin

6条回答
  •  难免孤独
    2021-01-02 20:10

    function pojo_polylang_get_multilang_logo( $value ) {
    if ( function_exists( 'pll_current_language' ) ) {
        $logos = array(
            'en' => 'logo-en.png',
            'in' => 'logo-in.png',
        );
        $default_logo = $logos['en'];
        $current_lang = pll_current_language();
        $assets_url = get_stylesheet_directory_uri() . '/assets/images/';
        if ( isset( $logos[ $current_lang ] ) )
            $value = $assets_url . $logos[ $current_lang ];
        else
            $value = $assets_url . $default_logo;
    }
    return $value;
    }
    add_filter( 'theme_mod_image_logo', 'pojo_polylang_get_multilang_logo' );
    

    if you have a look from $assets_url to $return $value you will see an if statement :

            $assets_url = get_stylesheet_directory_uri() . '/assets/images/';
        if ( isset( $logos[ $current_lang ] ) )
            $value = $assets_url . $logos[ $current_lang ];
        else
            $value = $assets_url . $default_logo;
    }
    return $value
    

    from what I am looking at I can see an error as the if statement does not include {} maybe if you changed it to the following it might work?

            $assets_url = get_stylesheet_directory_uri() . '/assets/images/';
        if ( isset( $logos[ $current_lang ] ) ) {
            $value = $assets_url . $logos[ $current_lang ];
        } else {
            $value = $assets_url . $default_logo;
        }
    }
    return $value
    

提交回复
热议问题