当我单击其他语言时,WordPress更改徽标图像 [英] WordPress Change logo image when I click to a different language

查看:83
本文介绍了当我单击其他语言时,WordPress更改徽标图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多语言网站.切换到印度"后,是否可以将logo.png更改为其他.png?我目前正在使用polylang插件.我尝试了此解决方案,但没有成功- https://support. pojo.me/docs/polylang-change-logo-every-language/.

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 at this moment. I tried this solution but it did not work - https://support.pojo.me/docs/polylang-change-logo-every-language/.

有人知道如何解决此问题吗?

Does any one know how to fix this issue?

我的代码

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' );

推荐答案

对于包含14个类别的博客,我们几乎做了同样的事情,每个类别都必须显示自己的徽标.

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

在我们的案例中,我们使用了自定义的php代码,该代码将检查url并相应地覆盖主题中的徽标显示,同时从数据库的徽标路径中获取徽标.

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.

在您的情况下,应该更容易,因为语言变量易于访问,因此您需要在主题的header.php中做的是围绕徽标的if语句,同时从数据库中提取徽标图像(最好从数据库中获取徽标图像).选项表),具体取决于语言.

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());

?> <img class="logo" src="<?php echo $logo_image; ?>"

希望这就是您想要的.

这篇关于当我单击其他语言时,WordPress更改徽标图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆