0

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.

bogdan
  • 667
  • 1
  • 8
  • 17
  • I will remove change_logo() and try to do something like this instead: – Jack Luo Feb 01 '19 at 21:09
  • That would be simple but I need the user to be able to upload their own logos. The logo changes every year. And asking them to delete the old ones and precisely name the new ones each year is a shoddy solution. – bogdan Feb 01 '19 at 21:13
  • I see. You may want to create a plugin for your user in this case. something like this?: https://blog.idrsolutions.com/2014/06/wordpress-plugin-part-1/ – Jack Luo Feb 01 '19 at 21:18

0 Answers0