Created
December 13, 2020 15:35
-
-
Save prosantamazumder/c73f64da94e086b8dc82f189a28c57b8 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
// Google Font Function | |
/** | |
//Using a single key and value: | |
<add_query_arg( 'key', 'value', 'http://example.com' ); | |
//Using an associative array: | |
add_query_arg( array( | |
'key1' => 'value1', | |
'key2' => 'value2', | |
), 'http://example.com' ); | |
*/ | |
function university_google_fonts_url() { | |
$fonts_url = ''; | |
$Montserrat = _x( 'on', 'Playfair Display font: on or off', 'university' ); | |
$open_sans = _x( 'on', 'Open Sans font: on or off', 'university' ); | |
if ( 'off' !== $Montserrat || 'off' !== $open_sans ) { | |
$font_families = array(); | |
if ( 'off' !== $Montserrat ) { | |
$font_families[] = 'Montserrat:100,200,300,400,500,600,700,800,900'; | |
} | |
if ( 'off' !== $open_sans ) { | |
$font_families[] = 'Open Sans:400,700,900'; | |
} | |
$query_args = array( | |
'family' => urlencode( implode( '|', $font_families ) ), | |
'subset' => urlencode( 'latin,latin-ext' ), | |
); | |
$fonts_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' ); | |
} | |
return esc_url_raw( $fonts_url ); | |
} | |
function fictional_university(){ | |
//Normal Way | |
wp_enqueue_style( 'google-fonts', '//fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,400;0,700;1,400;1,700&display=swap', false ); | |
Themeforest Themes | |
wp_enqueue_style( 'university-google-fonts', university_google_fonts_url(), array(), '1.0.0' ); | |
} | |
add_action( 'wp_enqueue_scripts', 'fictional_university' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment