Site logo

Archived topic

Force Locally Hosted Fonts

32 replies · Started by Simon on March 11, 2019

Viewing posts 16–30 of 33

In that case, I'm guessing you have some sort of caching going on.

You could try naming the font something else, like "Custom Lato". You'd need to rename it in the @font-face definitions and the custom function adding it to the Customizer.

Ok, i tried that, i changed it to Lato-Custom. Now it makes a call to google for "Lato-Cutom"?
I also cleared all the caches.

Can you share all of the custom functions related to this that you're using? Be sure to highlight the code in the editor and click the "code" button.

Sure thing. If I have understood you correctly, your just referring to the php i have added to the snippet plugin. Its just this, and its set to "Only run in administration area":

add_filter( 'generate_typography_default_fonts', function( $fonts ) {
    $fonts[] = 'Lato-Custom';

    return $fonts;
} );

Weird - any chance you can send me temporary admin login details so I can take a closer look?: https://generatepress.com/contact

If so, be sure to mention this topic.

Thanks!

Definitely something weird going on here - I assume there's something cache related that's broken.

Let's try adding this function:

add_action( 'wp_enqueue_scripts', function() {
    wp_dequeue_style( 'generate-fonts' );
}, 100 );

Ah thats really frustrating, I tried disabling WPRocket, and clearing the WPengine caches too.

It seems the code you gave me is working though. What is it doing?

Any thoughts how i can get to the root cause of the issue?

Cheers,
Simon

The code I just provided tells GeneratePress to not load Google Fonts, no matter what.

By default, if a font is provided in the generate_typography_default_fonts filter, it won't trigger Google Fonts. For some reason, your website is ignoring that logic and trying to call Google anyways.

I'll do some digging to see if there's a bug somewhere.

Ah gotcha. I think thats a good solution, as is unlikely to cause any issues.

Ah ignoring logic, thats something I am unfortunately very familiar with :)

Thank you SOOOO much Tom for your ongoing and dedicated support. I really appreciate it.

Regards,
Simon

Glad I could help! :)

Hi Tom,

Just a note on this, that it still happening.

I only noticed it on a site I am currently building by chance today and when back to check my other sites. The same issue, GeneratePress was reverting to the Google Font and "not" the local version when I left the Customiser.

Using the following code:

add_action( 'wp_enqueue_scripts', function() {
    wp_dequeue_style( 'generate-fonts' );
} );

...did not solve the issue. ( I tried both with the priority of 100 and without ).

My site is hosted with SiteGround ( the original person in this thread was hosted with WP Engine ) and I can confirm that even with the SG Optimiser, WP Rocket and Cloudflare disabled nothing worked, except for adding the code above.

I am running my own child theme ( I'm not sure about the person that opened this ticket ) but the only code I use to activate the child theme is:

function generatepress_child_enqueue_scripts() {
	if ( is_rtl() ) {
		wp_enqueue_style( 'generatepress-rtl', trailingslashit( get_template_directory_uri() ) . 'rtl.css' );
	}
}
add_action( 'wp_enqueue_scripts', 'generatepress_child_enqueue_scripts', 100 );

The only thing that worked for me was using this code:

add_action( 'wp_enqueue_scripts', function() {
    wp_dequeue_style( 'generate-fonts' );
} );

Kind regards,

Simon

Hi Simon,

Can you share the function you're using to add your custom font to the Customizer?

Hi Tom,

( Just catching on the original author was also called Simon )

I used the code from the Knowledge Base.

Specifically:

add_filter( 'generate_typography_default_fonts', function( $fonts ) {
    $fonts[] = 'Open Sans';

    return $fonts;
} );

With the font family changed appropriately. ( Sorry, not at my machine )

Kind regards,

Simon

Did you change the font name at all? I have seen a conflict where the custom font name matches a Google font.

Hi Tom,

Yup, the font name is changed to a Google Font so that I'm hosting the Google Font locally to improve web performance.

I do this for all my sites. There are only a couple of sites that use Fonts which aren't actually Google Fonts.

Kind regards,

Simon

This archived topic is closed to new replies.