Archived topic
Custom WOFF2 font not loading
3 replies · Started by Gabriele on July 15, 2021
Hey guys!
I've just followed this tutorial on how to add custom font https://docs.generatepress.com/article/adding-local-fonts/
but, although I can choose it from the Customize/Typography settings, I don't think it's loading at all.
Here is the code I have added to Simple CSS:
@font-face {
font-family: "Monty";
src: url(public_html/wearefesta/wp-content/themes/generatepress/assets/fonts/Monty-Bold-Trial.woff2) format("woff2"), url(public_html/wearefesta/wp-content/themes/generatepress/assets/fonts/Monty-Bold-Trial.woff) format("woff");
font-weight: bold;
}
@font-face {
font-family: "Monty";
src: url(public_html/wearefesta/wp-content/themes/generatepress/assets/fonts/Monty-Light-Trial.woff2) format("woff2"), url(public_html/wearefesta/wp-content/themes/generatepress/assets/fonts/Monty-Light-Trial.woff) format("woff");
font-weight: normal;
}
and here is the PHP snippet I have created:
add_filter( 'generate_typography_default_fonts', function( $fonts ) {
$fonts[] = "Monty";
return $fonts;
} );
Hope you can help with this!
Cheers,
G
Hi there,
first off DONT add them to the Parent Themes folders as any changes you make will be lost when you update the Theme,
You should use a Child Theme or add them to the Media Library as explained in the DOC:
https://docs.generatepress.com/article/adding-local-fonts/
Then you must ensure the url in your @font-face src is the exact full URL to the files. Including the HTTPS:: domain
Okay, I see!
So I did that and it works now, thanks for your help David!
Alwasy great!
G
Really glad to hear that!