Created
December 27, 2018 19:33
-
-
Save brianpurkiss/eaab499eb473d51fdd763df3d8be1ce4 to your computer and use it in GitHub Desktop.
Adding Google Fonts to WordPress functions
This file contains 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 and optimize Google Fonts | |
// | |
// Add Google Fonts | |
// Enqueue google api webfont | |
function mod_fonts_enqueue() { | |
wp_register_script('font-loader', '//ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js', array(), false, true); | |
wp_enqueue_script('font-loader'); | |
} | |
// Set the font family | |
function mod_setup_google_fonts() { | |
echo " | |
<script> | |
WebFont.load({ | |
google: { | |
families: ['Roboto Condensed:400,700'] | |
} | |
}); | |
</script> | |
"; | |
} | |
// Adding DNS Prefetching | |
function mod_fonts_dns_prefetch() { | |
echo '<link rel="dns-prefetch" href="//fonts.googleapis.com" />'; | |
} | |
add_action( 'wp_enqueue_scripts', 'mod_fonts_enqueue' ); | |
add_action('wp_footer', 'mod_setup_google_fonts', 1000); | |
add_action('wp_head', 'mod_fonts_dns_prefetch', 0); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment