WordPress Change logo image when I click to a different language

后端 未结 6 896
佛祖请我去吃肉
佛祖请我去吃肉 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:28

    We have done almost the same on a blog that contains 14 categories, and each category had to display its own logo.

    In our case, we used custom php code, that checks in the url and overrides the logo display in the theme accordingly, while fetching the logo from the logo path from the db.

    In your case, it should be easier since the language variable is easily accessible, so all you need to do in your theme's header.php is a if statement around the logo while fetching the logo image from the database (preferably from the options table) depending on the language.

    //fetch the current language ( you can use https://polylang.pro/doc/function-reference/)
    
    $current_language = pll_current_language();
    
    //while fetching the logo for the current language, it's best if you add a fallback to the default language in case the option for the current language is not set
    
    $logo_image = get_option("logo_".$current_language,"logo_".$pll_default_language());
    
    ?> 

    Hope this is what you're looking for.

提交回复
热议问题