Swap header logo based on Polylang Locale


I have a client who needs me to swap the logo based on whether the language in use is English or French. The variable $lang should output the locale in this case of either en-CA or fr-CA for Canadian English or Canadian French.

I tried some code in my child functions.php :.

add_filter('nakb_logo','nakb_change_logo');
function nakb_change_logo($logo)
{
    echo $lang=get_bloginfo("language");
 $lang = pll_current_language('locale');

 switch ($lang) {
    case 'en-CA':
        $logo = "http://mydomain.com/wp-content/uploads/2017/09/logo.png";
        break;
    case 'fr-CA':
        $logo = "http://mydomain.com/wp-content/uploads/2017/09/logo_fr.png";
        break;
 }

 return $logo;
}

Doesn't break anything but doesn't do anything either. I have replaced the domain name here with mydomain.com because of client confidentiality but I verified my paths are correct and everything.

Any guidance as to how I might otherwise detect the language and swap out the standard Beans header logo appreciated. Perhaps I can unhook the function that places the logo and make a new widget hit area and put 2 image widgets in there, one localized to FR and the other to EN. But if I do that Beans drops the whole div structure that I have styled painstakingly. I want to keep your CSS, but swap the image only.

Thanks!


I don't know how to filter the logo source, but you could remove the logo, localise it, then stick it back in...

add_action( 'wp', 'remove_brand_logo' );

function remove_brand_logo() {

    beans_remove_markup('beans_logo_image');

}

add_action( 'beans_site_title_link_append_markup', 'localise_and_add_logo' );

function localise_and_add_logo() {

    $lang = get_bloginfo("language");

    switch ($lang) {
        case 'en-CA':
            $logo = "http://mydomain.com/wp-content/uploads/2017/09/logo.png";
            break;
        case 'fr-CA':
            $logo = "http://mydomain.com/wp-content/uploads/2017/09/logo_fr.png";
            break;
    }

    ?>

    <img class="tm-logo" src="<?php echo $logo; ?>" alt="" data-markup-id="beans_logo_image">

    <?php

}

Write a reply

Login or register to write a reply, it's free!