In this tutorial, I’ll show how to load Google Fonts or any other CSS file using functions.php.
It’s important to load such scripts via functions.php
if you’re using CSS/JS minifying plugins.
Let’s create a new function google_fonts()
inside functions.php
and then register it with wp_print_styles
. This function will load selected Ubuntu font styles from Google Fonts.
// Register style sheet.
add_action( 'wp_print_styles', 'google_fonts' );
/**
* Register style sheet.
*/
function google_fonts() {
wp_register_style( 'Ubuntu', '//fonts.googleapis.com/css?family=Ubuntu:400,400i,700' );
wp_enqueue_style( 'Ubuntu' );
}
That’s it, Ubuntu font styles will now be loaded in the site header.
If you find this post useful, please let me know in the comments below.
Cheers,
Renat Galyamov
Want to share this with your friends?
👉renatello.com/wordpress-google-fonts
PS: make sure you check other WordPress tutorials, e.g. how to remove emoji CSS from WordPress, why you should kill Disqus on your WordPress blog and download my plugin that improves your WordPress SEO & Performance.