transmitstudio
7/22/2014 - 6:54 PM

proper way to add google fonts to wordpress

<?php

add_action( 'wp_enqueue_scripts', 'child_load_google_fonts' );
/**
 * Enqueue Google Fonts using a function
 * via Rickaby http://gregrickaby.com/add-google-fonts-wordpress-right-way/
 */
function child_load_google_fonts() {

	// Find out which http protocol our server is, so we can match google
  	$protocol = is_ssl() ? 'https' : 'http';
  	
  	// 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, "$protocol://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' );
}