How to Add Google Fonts to WordPress Themes Properly

Updated reading time

Google fonts are some of the most useful and the most well-known web fonts out there on the internet today. Its free-to-use nature makes it easy to adopt to websites.

Why Use the Functions.php File to Load Google Fonts

There are different kinds of methods for adding google fonts to the WordPress website or theme. But it will be more convenient to discontinue using a plugin to load the Google Fonts.

The reason why it isn’t optimal to use a Google Fonts plugin is that you want the fonts to display for the particular theme.

But what if you were to suddenly change themes. And probably the new theme developer forgot to disable the Google Fonts plugin in your array of plugins on your website?

That would make for an additional HTTP request, for a set of Google Fonts that might never be used again.

Therefore you will be adding the Google Fonts to the theme’s functions.php to keep things (a) organised, and (b) intentional.

So in your functions.php file of your theme, add this snippet of code:

The snippet will load your ‘google-fonts’ CSS stylesheet properly this way, within the <head> element of your website. It will be best to add all of your Google fonts within the 1 URL that says __YOUR_FONT_URL_HERE__ so that no matter how many Google fonts you will be loading, it will still be considered 1 request for your browser.

The function name is kept ambiguous since this will indicate that to anyone who comes across your functions.php file you are to be loading all your Google fonts in this 1 function.

Related:  How to Install a Collection of WordPress Plugins

Alternatives to Adding Google Fonts Not in Functions.php

If for some reason you are not able to access the functions.php file of the theme or would be able to save it in your theme, you can try this out.

Yes, now you can opt for a Google Fonts plugin. However please note that this is an easy but prone-to-danger approach to adding Google Fonts.

Takeaway

However with this article I hoped it has shed light on the proper way of adding Google fonts to your WordPress theme or website.

Make sure that you have it loaded through your theme’s functions.php file first. But if you can not for some reason, then that will be the time to use the Google Fonts plugin.