Skip to content

Instantly share code, notes, and snippets.

@hmbashar
Last active September 13, 2019 19:08
Show Gist options
  • Save hmbashar/a0d3b57c4bc4640e223de87850068155 to your computer and use it in GitHub Desktop.
Save hmbashar/a0d3b57c4bc4640e223de87850068155 to your computer and use it in GitHub Desktop.
google font enqueue for wordpress theme and plugins
<?php
wp_enqueue_style( 'prefix-google-font', finestudio_get_google_font_url() );
<?php
// Google Fonts
function finestudio_get_google_font_url() {
$font_url = '';
/* Translators: If there are characters in your language that are not
* supported by Arizonia, translate this to 'off'. Do not translate
* into your own language.
*/
$Lato = _x( 'on', 'Lato font: on or off', 'massive' );
/* Translators: If there are characters in your language that are not
* supported by Source Sans Pro, translate this to 'off'. Do not translate
* into your own language.
*/
$Montserrat = _x( 'on', 'Montserrat font: on or off', 'massive' );
if ( 'off' !== $arizonia || 'off' !== $Montserrat ) {
$font_families = array();
if ( 'off' !== $Lato ) {
$font_families[] = 'Lato';
}
if ( 'off' !== $Montserrat ) {
$font_families[] = 'Montserrat:300,300i,400,400i,500,500i,600,600i,700';
}
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$font_url = add_query_arg( $query_args, '//fonts.googleapis.com/css' );
}
return esc_url_raw( $font_url );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment