astra_get_font_css_value( string $value, string $unit = 'px', string $device = 'desktop' )
Get Font CSS value
Description
Syntax:
astra_get_font_css_value( VALUE, DEVICE, UNIT );
E.g.
astra_get_css_value( VALUE, ‘desktop’, ‘%’ ); astra_get_css_value( VALUE, ‘tablet’ ); astra_get_css_value( VALUE, ‘mobile’ );
Parameters
- $value
-
(string) (Required) CSS value.
- $unit
-
(string) (Optional) CSS unit.
Default value: 'px'
- $device
-
(string) (Optional) CSS device.
Default value: 'desktop'
Return
(mixed) CSS value depends on $unit & $device
Source
File: inc/core/common-functions.php
function astra_get_font_css_value( $value, $unit = 'px', $device = 'desktop' ) { // If value is empty then return blank. if ( '' == $value || ( 0 == $value && ! astra_zero_font_size_case() ) ) { return ''; } $css_val = ''; switch ( $unit ) { case 'em': case '%': $css_val = esc_attr( $value ) . $unit; break; case 'px': if ( is_numeric( $value ) || strpos( $value, 'px' ) ) { $value = intval( $value ); $fonts = array(); $body_font_size = astra_get_option( 'font-size-body' ); $fonts['desktop'] = ( isset( $body_font_size['desktop'] ) && '' != $body_font_size['desktop'] ) ? $body_font_size['desktop'] : 15; $fonts['tablet'] = ( isset( $body_font_size['tablet'] ) && '' != $body_font_size['tablet'] ) ? $body_font_size['tablet'] : $fonts['desktop']; $fonts['mobile'] = ( isset( $body_font_size['mobile'] ) && '' != $body_font_size['mobile'] ) ? $body_font_size['mobile'] : $fonts['tablet']; if ( $fonts[ $device ] ) { $css_val = esc_attr( $value ) . 'px;font-size:' . ( esc_attr( $value ) / esc_attr( $fonts[ $device ] ) ) . 'rem'; } } else { $css_val = esc_attr( $value ); } } return $css_val; }
Expand full source code Collapse full source code View on Trac