/**
* Google Font URL
* Combine multiple google font in one URL
* @link https://shellcreeper.com/?p=1476
* @author David Chandra <[email protected]>
*/
function tamatebako_google_fonts_url( $fonts, $subsets = array() ){
/* URL */
$base_url = "//fonts.googleapis.com/css";
$font_args = array();
$family = array();
/* Format Each Font Family in Array */
foreach( $fonts as $font_name => $font_weight ){
$font_name = str_replace( ' ', '+', $font_name );
if( !empty( $font_weight ) ){
if( is_array( $font_weight ) ){
$font_weight = implode( ",", $font_weight );
}
$family[] = trim( $font_name . ':' . urlencode( trim( $font_weight ) ) );
}
else{
$family[] = trim( $font_name );
}
}
/* Only return URL if font family defined. */
if( !empty( $family ) ){
/* Make Font Family a String */
$family = implode( "|", $family );
/* Add font family in args */
$font_args['family'] = $family;
/* Add font subsets in args */
if( !empty( $subsets ) ){
/* format subsets to string */
if( is_array( $subsets ) ){
$subsets = implode( ',', $subsets );
}
$font_args['subset'] = urlencode( trim( $subsets ) );
}
return add_query_arg( $font_args, $base_url );
}
return '';
}
$google_fonts_url = tamatebako_google_fonts_url(
array(
'Open Sans' => array( '400', '600' ),
'Anton' => array(),
),
array( 'latin', 'latin-ext' )
);
wp_enqueue_style( 'my-google-fonts', $google_fonts_url );
#in Footer
function pugmarker_new_scripts_footer() {
$google_fonts_url = tamatebako_google_fonts_url(
array(
'Open Sans' => array( '400', '600' ),
'Anton' => array(),
),
array( 'latin', 'latin-ext' )
);
wp_enqueue_style( 'my-google-fonts', $google_fonts_url );
}
add_action( 'wp_footer', 'pugmarker_new_scripts_footer' );