Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wordpress google fonts Dynamic
//Refarence themeshaper
function theme_name_fonts_url() {
$fonts_url = '';
$OpenSans = _x( 'on', 'OpenSans font: on or off', 'theme-slug' );
$Montserrat = _x( 'on', 'Montserrat font: on or off', 'theme-slug' );
if ( 'off' !== $OpenSans || 'off' !== $Montserrat ) {
$font_families = array();
if ( 'off' !== $OpenSans ) {
$font_families[] = 'Open+Sans:300i,400,400i,600,700,800';
}
if ( 'off' !== $Montserrat ) {
$font_families[] = 'Montserrat:200,300,400,500,600,700,800,900';
}
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'cyrillic-ext,cyrillic,vietnamese,latin-ext,latin,greek-ext,greek')
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return $fonts_url;
}
//wp_enqueue_style( 'theme-slug-fonts', theme_name_fonts_url(), array(), null );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment