Archived topic
The Fastest Google Fonts - functions.php
5 replies · Started by Julian on November 23, 2020
Is there a way to use this technique for loading google fonts from google cdn in the functions.php?
Hi,
To clarify: do you need these codes added to your site's <head>?
You can do that by either placing these <link> markups on a Hook Element that is hooked to wp_head.
https://docs.generatepress.com/article/hooks-element-overview/
or,
place this PHP snippet on your child theme's functions.php.
add_action( 'wp_head', function () { ?>
// your code here. presumably the <link> ones.
<?php } );
I was more looking for an "out of the box" solution in form of a functions.php for externally hosted google webfonts. Soemthing that "hooks into" when a google webfont is selected in the customizer. I know how to do it manually.
Hi there,
GeneratePress will preconnect Google fonts automatically.
It doesn't preload at the moment - we'll look into that during our Typography rewrite (scheduled for 3.1.0).
Awesome Tom, the workaround which I liked above improves the loading and pagespeed insights as well. Have a look at it :)
Added that link to our Typography re-write task :)
Thanks!