Last active
October 21, 2019 02:50
-
-
Save gregrickaby/4444021 to your computer and use it in GitHub Desktop.
Add Google Fonts to Wordpress (the right way)
This file contains 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
<?php | |
add_action( 'wp_enqueue_scripts', 'child_load_google_fonts' ); | |
/** | |
* Enqueue Google Fonts using a function | |
*/ | |
function child_load_google_fonts() { | |
// Setup font arguments | |
$query_args = array( | |
'family' => 'Open+Sans:300,400,700' // Change this font to whatever font you'd like | |
); | |
// A safe way to register a CSS style file for later use | |
wp_register_style( 'google-fonts', add_query_arg( $query_args, "//fonts.googleapis.com/css" ), array(), null ); | |
// A safe way to add/enqueue a CSS style file to a WordPress generated page | |
wp_enqueue_style( 'google-fonts' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think no need to use $protocol prefix.