Astra_Fonts::google_fonts_url( array $fonts, array $subsets = array() )
Google Font URL Combine multiple google font in one URL
Description
Parameters
- $fonts
-
(array) (Required) Google Fonts array.
- $subsets
-
(array) (Optional) Font's Subsets array.
Default value: array()
Return
(string)
Source
File: inc/customizer/class-astra-fonts.php
public static function google_fonts_url( $fonts, $subsets = array() ) { /* URL */ $base_url = 'https://fonts.googleapis.com/css'; $font_args = array(); $family = array(); // This is deprecated filter hook. $fonts = apply_filters( 'astra_google_fonts', $fonts ); $fonts = apply_filters( 'astra_google_fonts_selected', $fonts ); /* 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 ); } $font_family = explode( ',', $font_name ); $font_family = str_replace( "'", '', astra_get_prop( $font_family, 0 ) ); $family[] = trim( $font_family . ':' . rawurlencode( 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'] = rawurlencode( trim( $subsets ) ); } $font_args['display'] = astra_get_fonts_display_property(); return add_query_arg( $font_args, $base_url ); } return ''; }
Expand full source code Collapse full source code View on Trac