search ]

Add Google Fonts to WordPress

There are several ways to add Google Fonts to a WordPress site. Here are two of them. The first and less recommended option is to add the fonts directly to your theme’s header.php (preferably in a child theme).

<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Lora|Oswald" media="screen">

When using this method, note that you must add the Google Fonts call before you load the main stylesheet.

The second and more recommended option is using wp_register_style and wp_enqueue_style. Add the following code to your functions.php file:


function add_my_google_fonts() {

	wp_register_style('my-googleFonts', 'https://fonts.googleapis.com/css?family=Open+Sans:300italic,300,600,700,400');
    wp_enqueue_style( 'my-googleFonts');
}
add_action('wp_enqueue_scripts', 'add_my_google_fonts');

Avoid making two or more calls to Google’s servers – you can embed all fonts in a single call.

There is also an option for local embedding of Google fonts. Local embedding has several advantages – for more on this, see the post Loading Google Fonts locally.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo