How to Use Google Fonts, with wp_register_style & wp_enqueue_style

Snippets by IsItWP

Are you looking for a way to use Google Fonts with wp_register_style and wp_enqueue_style? While there’s probably a plugin for this, we have created a quick code snippet that you can use to include Google Fonts in WordPress.

Many people might want to include fonts by inserting HTML into wp_head(), but this method is by far the better way. You need to change the URL for the font you would like to use within your theme.


All you have to do is add this code to your theme’s functions.php file or in a site-specific plugin:

function wps_enqueue_fonts() {
	if (!is_admin()) {
		wp_register_style('font_roboto', 'https://fonts.googleapis.com/css?family=Roboto:400,300,500,700', array(), null, 'all');
		wp_register_style('font_oswald', 'https://fonts.googleapis.com/css?family=Oswald', array(), null, 'all');

add_action('wp_enqueue_scripts', 'wps_enqueue_fonts');

Note: If this is your first time adding code snippets in WordPress, then please refer to our guide on how to properly add code snippets in WordPress, so you don’t accidentally break your site.

If you liked this code snippet, please consider checking out our other articles on the site like: 7 best VPN services for WordPress and how to create a WordPress donation form.

Comments   Leave a Reply

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

WordPress Launch Checklist

The Ultimate WordPress Launch Checklist

We've compiled all the essential checklist items for your next WordPress website launch into one handy ebook.
Yes, Send Me the Free eBook!