WordPress Code Snippets

A fresh mix of code snippets and tutorials

The Right Way to Include Google Fonts in WordPress


This tutorial explains the right (and wrong) way to include (aka enqueue) Google Fonts in your WordPress theme.

The WRONG way to enqueue Google fonts

First let’s look at the wrong way to enqueue Google fonts, then we’ll see how to do it the right way. I see this unsavory technique used in various themes and plugins (including one of my own from a couple of years ago!):

Sure it works, but it is not according to WordPress best practices or WP API, which should be top priority for anyone developing WordPress stuff. This method basically adds the Google Font <link> tag by filtering wp_head. Definitely the wrong way to enqueue Google fonts.

The RIGHT way to enqueue Google fonts

Here is the correct approach, according to the WP API and best practices:

Here we are registering the Google Font stylesheet using wp_register_style(), and then enqueueing it with wp_enqueue_style(). This enables us to customize the output of the <link> tag by changing the parameters:

wp_register_style($handle, $src, $deps, $ver, $media);

Learn more about these functions at the WordPress Codex.


Learn more

WordPress Themes In Depth

Show Support

Like our new Facebook Page to show support!