Font-Style Issue
whenever i try to display the typography output myself. it shows following error
Notice: Undefined index: font-style in C:\xampp\htdocs\marudha\wp-content\themes\marudha\framework\custom-css.php on line 545
Here is the code i use
$options = get_option('marudha');
$body_font = $options['body_font'];
if( $body_font !== '' ) {
$body_font_weight = isset($body_font['font-weight']) ? $body_font['font-weight'] : "";
$body_font_style = isset($body_font['font-weight']) ? $body_font['font-style'] : "";
}
Here is the print_r output
Array ( [font-family] => Lora [font-options] => {"variants":[{"id":"400","name":"Normal+400"},{"id":"700","name":"Bold+700"},{"id":"400italic","name":"Normal+400+Italic"},{"id":"700italic","name":"Bold+700+Italic"}],"subsets":[{"id":"cyrillic","name":"Cyrillic"},{"id":"latin-ext","name":"Latin+Extended"},{"id":"latin","name":"Latin"}]} [google] => true [font-weight] => 400 [font-style] => italic [subsets] => [text-transform] => [font-size] => 14px )
All are working fine except font-style. I'm using Redux v3.1.8.18.
Umm, your second isset is for font-weight, when you're providing font-style. ;)
Here's how to do it properly.
global $marudha;
if ( isset( $marudha['body_font'] ) && !empty( $marudha['body_font'] ) ) {
$body_font_weight = isset($marudha['body_font']['font-weight']) ? $marudha['body_font']['font-weight'] : "";
$body_font_style = isset($marudha['body_font']['font-style']) ? $marudha['body_font']['font-style'] : "";
}
Of course, you could save yourself a whole TON of trouble and use the output or compiler argument instead and let Redux build your CSS for you...
Oh and no need to do get_option just use your opt_name as a global variable. No need to do extra DB calls.
@dovy Thanks
Just trying to save you time when it's already done for you. :)