I wan to write a function with switch() where I can pass option value for multiple object.
Code
<?php
function font_switch(){
if ($option == get_option('fm_font_family')) {
get_option('fm_font_family') ;
} else if ($option == get_option('fm_font_family_text')) {
get_option('fm_font_family_text') ;
}
switch($option){
case 'Choose font family':
return null;
break;
case 'Georgia, serif':
return 'Georgia, serif';
break;
case 'Palatino Linotype, Book Antiqua, Palatino, serif':
return 'Palatino Linotype, Book Antiqua, Palatino, serif';
break;
case 'Times New Roman, Times, serif':
return 'Times New Roman, Times, serif';
break;
case 'Arial, Helvetica, sans-serif':
return 'Arial, Helvetica, sans-serif';
break;
case 'Comic Sans MS, cursive, sans-serif':
return 'Comic Sans MS, cursive, sans-serif';
break;
case 'Impact, Charcoal, sans-serif':
return 'Impact, Charcoal, sans-serif';
break;
case 'Lucida Sans Unicode, Lucida Grande, sans-serif':
return 'Lucida Sans Unicode, Lucida Grande, sans-serif';
break;
case 'Tahoma, Geneva, sans-serif':
return 'Tahoma, Geneva, sans-serif';
break;
case 'Verdana, Geneva, sans-serif':
return 'Verdana, Geneva, sans-serif';
break;
default:
return '';
break;
}
}
?>
CSS
body{
font-family: <?php echo font_switch(get_option('fm_font_family')); ?>;
}
p{
font-family: <?php echo font_switch(get_option('fm_font_family_text')); ?>;
}
So in above function I want to pass option using get_option(‘my option id’) and want to use it for css as I am using same font family
If you have any other better option I can go for it too.
I would rewrite to this, since you’re almost always returning the same value: