While inspecting twentyseventeen theme I found that custom font is registered using below way –
/**
* Register custom fonts.
*/
function twentyseventeen_fonts_url() {
$fonts_url = '';
/*
* Translators: If there are characters in your language that are not
* supported by Libre Franklin, translate this to 'off'. Do not translate
* into your own language.
*/
$libre_franklin = _x( 'on', 'Libre Franklin font: on or off', 'twentyseventeen' );
if ( 'off' !== $libre_franklin ) {
$font_families = array();
$font_families[] = 'Libre Franklin:300,300i,400,400i,600,600i,800,800i';
$query_args = array(
'family' => urlencode( implode( '|', $font_families ) ),
'subset' => urlencode( 'latin,latin-ext' ),
);
$fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
}
return esc_url_raw( $fonts_url );
}
On many tutorial sites out there authors have recommended using below method –
function add_google_fonts() {
wp_enqueue_style( ‘google_web_fonts’, ‘https://fonts.googleapis.com/css?family=Open+Sans|Roboto’ );
}
add_action( ‘wp_enqueue_scripts’, ‘add_google_fonts’ );
What’s the difference b/w above two and what are their advantages and disadvantages?
]]>wp_enqueue_style
way as your 2nd example:
wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
To each his own!
]]>