I recently built a site for a client. I built it locally and tested hosting it via siteground with no issues. My client uses godaddy so I migrated the site over there. But when it’s hosted on godaddy there’s an issue loading font files.
I’m using a block theme. The font files are stored in the theme directory in `/assets/fonts`. Then they’re referenced in `theme.json` like so:
{
“settings”: {
“typography”: {
“fontFamilies”: [
{
“fontFace”: [
{
“fontDisplay”: “block”,
“fontFamily”: “Poppins”,
“fontStretch”: “normal”,
“fontStyle”: “normal”,
“fontWeight”: “400”,
“src”: [“file:./assets/fonts/Poppins-Regular.woff2”]
}
],
“fontFamily”: “Poppins, sans-serif”,
“name”: “Poppins”,
“slug”: “secondary”
}
]
}
}
}
When I load the godaddy site up the dev tools network tab shows the fonts aren’t being requested/loaded. What’s weird is they *are* being loaded in the site editor.
If it makes any difference I migrated the site over using the updraft plugin. But it worked fine going from local to siteground and vice versa.
[ad_2]
if I was you I’d get as far away from GoDaddy as possible. They’re a scam company.
It seems adding a redundant @font-face rule helps to get it working on godaddy. I wanted to use PHP to ensure the correct file path so I’m currently doing this in `functions.php`:
function fonts_workaround()
{
?>
<style>
@font-face{ font-display:swap;
font-family: ‘Poppins’;
src: url(‘<?php echo get_theme_file_uri(‘/assets/fonts/Poppins-Regular.woff2′) ?>’);
}
</style>
<?php
};
add_action(‘wp_head’, ‘fonts_workaround’);
Kind of janky but it works. If anyone knows a more graceful way let me know.