Use google fonts, with wp_register_style & wp_enqueue_style

This is a simple snippet that uses wp_register_style() & wp_enqueue_style() to include Google fonts. Many people might want to include fonts by inserting HTML into wp_head(), but this method is by far the better way. In this sample, I gave each font a unique handle based on the font name so we can easily see what's registered and enqueued. You will, of course, need to change the URL for the font you would like to use within your theme. Then, add this snippet to the functions.php file of your WordPress theme and you are good to go.

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');

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!