I am using the Polylang plugin for this. The theme is only bilingual, and I've managed to create a panel in the admin section for uploading the logos separately, registered to logo_sr and logo_es.
I now want to add a variable to the options table which will contain the URL to the logo which should be displayed, based on the current language. Here is what I've done so far:
I registered a new setting, logo_spanski_metar, for that purpose, and called it with admin_init:
register_setting('spanski-settings-group', 'logo_spanski_metar');
Then I used the following code to set its value based on the current language (HERE LIES THE PROBLEM, SOMEWHERE):
add_filter('logo_spanski_metar','change_logo');
function change_logo($logo) {
$lang = pll_current_language('locale');
switch ($lang) {
case 'sr_RS':
$logo = get_option( 'logo_sr') ;
break;
case 'es_ES':
$logo = get_option( 'logo_es') ;
break;
}
return $logo;
}
I know that the logo_sr and logo_es settings are saved properly because they work properly when I do this:
<img src="<?php echo get_option('logo_sr') ?>">
But the change_logo() function is messed up, the logo_spanski_metar variable remains empty.
Thank you for your time.
EDIT: I also know that the switch should be working correctly because I've echoed the pll_current_language('locale') function and it returns either sr_RS or es_ES.
EDIT 2: I solved the problem by forgetting about the third variable and just putting the switch directly in my header HTML. I am leaving this open in case someone can point out what I was doing wrong.