Site logo

Archived topic

Regarding hosting Google fonts locally

15 replies · Started by Chitika on December 3, 2020

Viewing posts 1–15 of 16

I would like to host the Google fonts I'm using for my site locally on my server.
In page speed tests, I see that loading these fonts externally is causing some increase in page load time.
Can you tell me how to implement it with GP.

Hi,
I have added a font - "Source Sans Pro" on my site for the body section as you said.
Now, in the Typography setting, I have selected it as system font.

In the Font Family section, I see 200, 200 italic, etc. kind of items.
Are they all required to be included. Or else I can delete them.

In the Font Family section, I see 200, 200 italic, etc. kind of items.
Are they all required to be included. Or else I can delete them.

You can remove them if you don't need them. :)

Few questions.

In the Font Family section, I see 200, 200 italic, etc. kind of items.
Are they all required to be included. Or else I can delete them.

You can remove them if you don’t need them. 🙂

1. If I delete them, can i get all of them back easily or do I need to add them individually.
2. Also, since I don't need the Google Fonts now, how to disable them.
3. From personal experience, do you think hosting Google fonts locally is a good idea.

Hi Chitika,

I recently read this article by WP Rocket: https://wp-rocket.me/blog/self-hosting-google-fonts/

From the article, it seems to suggest there is negligible difference in hosting fonts locally vs linking to google fonts.

Don't know if the GP team would agree with that :)

From the article, it seems to suggest there is negligible difference in hosting fonts locally vs linking to google fonts.

"Neglible" is relative to how nitpicky a person is. Some people are bothered by the 0.02 second difference. lol.

Kidding aside, that's actually true in some cases where the font query is well specified. But there are also sites where locally hosting fonts cuts the loading time by half as google font's render-blocking CSS can be an issue. And this is related to CLS issues reported by Google PSI on some sites.

Ha ha, 0.02 seconds improvement is the holy grail for some people lol.

I myself prefer to use the most popular google fonts (e.g. Roboto), as there is a distinct possibility that your visitor's browser has already cached that font from surfing other websites.

If you're going to use one of the more fancier fonts, then hosting locally would be beneficial.

Thanks Elvin.

Hi all,
sorry to jump in this conversation. I was also looking to host my fonts, but, following your article, when uploading the fonts to the Media Library (after adding the php code), the .tff files still cannot be uploaded "for security reasons". All the other files type are uploaded without a problem.
Is this an error you can reproduce? Or have an idea what could be causing it?
Thanks a lot

Hi all,
sorry to jump in this conversation. I was also looking to host my fonts, but, following your article, when uploading the fonts to the Media Library (after adding the php code), the .tff files still cannot be uploaded “for security reasons”. All the other files type are uploaded without a problem.
Is this an error you can reproduce? Or have an idea what could be causing it?
Thanks a lot

Hi @Clemence,

If WordPress doesn't .tff file uploads, you'll have to add in a snippet that allows it.

Example:

add_filter('upload_mimes', 'add_custom_upload_mimes');
    function add_custom_upload_mimes($existing_mimes) {
        $existing_mimes['ttf'] = 'application/x-font-ttf';
        return $existing_mimes;
}

Hi Elvin,

Thanks for your fast reply. What I am saying is, even with the php snippet (the one you gave me here or the one we can find in the GP article), it still doesn't work. On my side at least.

Hi,

Can you try checking your file here for it's mime type?
https://wp-check-mime-type.com/

It also provides the snippet when you check.

If it still has issues, can you link us to the .ttf file? To test on other servers if it works.

Let us know.

Yup still doesn't work :(
I downloaded the files for Montserrat from this website, for regular, italic, 700 and 700 italic.

Cheers

Strange.

If you have access to FTP, you can edit your site's wp-config.php and set this:

define('ALLOW_UNFILTERED_UPLOADS', true);

This allows ALL files to be uploaded. After setting this, you should be able to upload your .TTF or any file.

Note: It is not recommended to keep this setting open as it exposes your site to potential threats. After uploading your file, make sure to disable this again.

Alternatively, try using plugins that lets you upload your font files.

Sadly I don't have access to FTP. Thanks for your help!

This archived topic is closed to new replies.