Site logo

Archived topic

Localize Google fonts

5 replies · Started by Joy on January 4, 2021

Viewing posts 1–6 of 6

Hi there GP Team, Happy New Year! Hope you were all able to take a little break.

We've recently had a site speed audit and our advisor has suggested localizing Google Fonts and suggested you might be able to help. I have had a look around the forum and found some similar topics but it all seems a little beyond me. Wondering if there is a simple way to do this?

Many thanks in advance,
Joy

Did you mean adding a font from google that isn't currently added on the customizer?

If that's the case, try this:
https://docs.generatepress.com/article/customizing-the-google-font-list/

It's the same link Leo provided on the thread.

The last PHP snippet on the documentation allows you to "localize" a font to the customizer.

Here's how to add PHP - https://docs.generatepress.com/article/adding-php/

Note: If its not from Google and is from something else, you'll have to create your own @font-face import on CSS and add it in on the customizer this way.

add_filter( 'generate_typography_default_fonts','tu_add_system_fonts' );
function tu_add_system_fonts( $fonts ) {
$fonts[] = 'Font Family name here';
return $fonts;
}

Where $fonts[] value is the font-family property value of the @font-face you've imported.

Thanks Elvin,

I don't think this is quite it but I don't know enough to be sure! Let me close this thread and come back when I've figured out exactly what our advisor wants us to do.

Many thanks,
Joy

No problem.

You can keep this open if you want so you can comeback to this incase you need further clarification/s. :)

This archived topic is closed to new replies.