Created
January 3, 2018 19:54
-
-
Save ikamal7/4762f4fd5d5660e487d39575378af14e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! function_exists( 'name_fonts_url' ) ) : | |
/** | |
* Register Google fonts for Your theme | |
* | |
* Create your own name_fonts_url() function to override in a child theme. | |
* | |
* @return string Google fonts URL for the theme. | |
*/ | |
function name_fonts_url() { | |
$fonts_url = ''; | |
$fonts = array(); | |
$subsets = 'latin,latin-ext'; | |
/** | |
* cs_get_options from Codestar framework | |
* 'body_font' from codestar typography field | |
* 'body_font_variants' from codestar Checkbox field | |
*/ | |
$body_font = cs_get_option('body_font'); | |
$body_font_variants_array = cs_get_option('body_font_variants'); | |
$body_font_variants = implode(',', $body_font_variants_array); | |
/** | |
* cs_get_options from Codestar framework | |
* 'heading_font_enable' from codestar switcher field | |
* 'heading_font' from codestar typography field | |
* 'heading_font_variants' from codestar Checkbox field | |
*/ | |
$heading_font_enable = cs_get_option('heading_font_enable'); | |
$heading_font = cs_get_option('heading_font'); | |
$heading_font_variants_array = cs_get_option('heading_font_variants'); | |
$heading_font_variants = implode(',', $heading_font_variants_array); | |
/** | |
* Check Font family !empty | |
*/ | |
if(!empty($body_font)){ | |
$body_font_family = $body_font['family']; | |
}else{ | |
$body_font_family = 'Montserrat'; | |
} | |
if(!empty($heading_font)){ | |
$heading_font_family = $heading_font['family']; | |
}else{ | |
$heading_font_family = 'Montserrat'; | |
} | |
$fonts[] = ''. esc_attr( $body_font_family ) .':'.esc_attr($body_font_variants).''; | |
if($heading_font_enable == true){ | |
$fonts[] = ''. esc_attr( $heading_font_family ) .':'.esc_attr($heading_font_variants).''; | |
} | |
if ( $fonts ) { | |
$fonts_url = add_query_arg( array( | |
'family' => urlencode( implode( '|', $fonts ) ), | |
'subset' => urlencode( $subsets ), | |
), 'https://fonts.googleapis.com/css' ); | |
} | |
return $fonts_url; | |
} | |
endif; | |
/** | |
* Enqueue this style in your enqueu function | |
*/ | |
wp_enqueue_style( 'industry-fonts', industry_fonts_url(), array(), null ); | |
/** | |
* Add custom Style file in your theme | |
* | |
* Inc the file with functions.php | |
* | |
* Inc a custom.css file in your theme | |
*/ | |
function industry_custom_css() { | |
wp_enqueue_style( 'industry_custom', get_template_directory_uri(). '/assets/css/custom.css' ); | |
$body_font = cs_get_option('body_font'); | |
$body_font_variant = $body_font['variant']; | |
$body_font_size = cs_get_option('body_font_size'); | |
$heading_font_enable = cs_get_option('heading_font_enable'); | |
$heading_font = cs_get_option('heading_font'); | |
$heading_font_variant = $heading_font['variant']; | |
if(!empty($body_font)){ | |
$body_font_family = $body_font['family']; | |
}else{ | |
$body_font_family = 'Montserrat'; | |
} | |
if(!empty($heading_font)){ | |
$heading_font_family = $heading_font['family']; | |
}else{ | |
$heading_font_family = 'Montserrat'; | |
} | |
$custom_css = ''; | |
$custom_css .= ' | |
body{ | |
font-family: '. esc_html( $body_font_family) .'; | |
font-weight: '. esc_html( $body_font_variant) .'; | |
font-size: '. esc_html( $body_font_size) .'; | |
} | |
'; | |
if($heading_font_enable == true){ | |
$custom_css .= 'h1, h2, h3, h4, h5, h6 { | |
font-family: '. esc_html( $heading_font_family) .'; | |
font-weight: '. esc_html( $heading_font_variant) .'; | |
}'; | |
} | |
wp_add_inline_style( 'industry_custom', $custom_css ); | |
} | |
add_action( 'wp_enqueue_scripts', 'industry_custom_css' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment