Last active
January 7, 2024 14:28
-
-
Save briankompanee/f5bc0cd75eb86424307f079c78138bb7 to your computer and use it in GitHub Desktop.
WordPress: Add Google Font support to the Sage theme for roots.io
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding resource hinting can further improve performance when using Google Fonts from Google Fonts CDN:
https://discourse.roots.io/t/prefetch-preload-resources/9179