Skip to content

Instantly share code, notes, and snippets.

@briankompanee
Last active January 7, 2024 14:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save briankompanee/f5bc0cd75eb86424307f079c78138bb7 to your computer and use it in GitHub Desktop.
Save briankompanee/f5bc0cd75eb86424307f079c78138bb7 to your computer and use it in GitHub Desktop.
WordPress: Add Google Font support to the Sage theme for roots.io
<?php
/**
* Add your Google Fonts here.
* This is specifically for the theme Sage from roots.io and goes in config.php
* Change the font name, weights and styles to what you are using as needed.
*/
define('GOOGLE_FONTS', 'Oswald:400,300,700:latin');
<?php
/**
* Manage google fonts of load_google_font()
* This is specifically for the theme Sage from roots.io and goes in extras.php
* set GOOGLE_FONTS constant in config.php
*/
function load_google_fonts() {
if( ! defined( 'GOOGLE_FONTS' ) ) return;
echo '<link href="https://fonts.googleapis.com/css?family=' . GOOGLE_FONTS . '" rel="stylesheet" type="text/css" />'."\n";
}
add_action( 'wp_head', __NAMESPACE__ . '\\load_google_fonts' , 1);
@strarsis
Copy link

strarsis commented Jan 7, 2024

Adding resource hinting can further improve performance when using Google Fonts from Google Fonts CDN:
https://discourse.roots.io/t/prefetch-preload-resources/9179

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment