The right way to add Google Fonts to WordPress

Another quick service post from my archive of things that I need to add to my company blog but haven't done yet.

Today's topic: how to properly enqueue Google Fonts to your WordPress without a plugin.

I'll just pull the code straight out of my theme so that you can see how it would work. We're going to use the URL directly from Google here:

http://fonts.googleapis.com/css?family=Oswald:400,300,700

In your functions.php:

/**
 * Additional Styles
 * @since 1.0.0
 */

function child_styles() {
    if ( !is_admin() ) {

        // register styles
        wp_register_style('googlefont-oswald', 'http://fonts.googleapis.com/css?family=Oswald:400,300,700', array(), false, 'all');

        // enqueue styles
        wp_enqueue_style('googlefont-oswald');
    }
}

add_action('wp_enqueue_scripts', 'child_styles');

Repeat the inner part for additional fonts. In other words, register and enqueue each set inside the brackets. The function is called "child_styles()" because I would register all of my .css files inside of one function. You can call yours whatever you like.

I'm pretty sure a number of you will find that useful.

Cheers,
Ian