Skip to content

Instantly share code, notes, and snippets.

@gregrickaby
Last active October 21, 2019 02:50
Show Gist options
  • Save gregrickaby/4444021 to your computer and use it in GitHub Desktop.
Save gregrickaby/4444021 to your computer and use it in GitHub Desktop.
Add Google Fonts to Wordpress (the right way)
<?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' );
}
@giiska
Copy link

giiska commented Jun 12, 2014

I think no need to use $protocol prefix.

@gregrickaby
Copy link
Author

I've removed it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment