[Resolved] Force Locally Hosted Fonts

Home Forums Support [Resolved] Force Locally Hosted Fonts

Home Forums Support Force Locally Hosted Fonts

Viewing 15 posts - 16 through 30 (of 33 total)
  • Author
    Posts
  • #841526
    Tom
    Lead Developer
    Lead Developer

    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.

    #842027
    Simon

    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.

    #842359
    Tom
    Lead Developer
    Lead Developer

    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.

    #842677
    Simon

    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;
    } );
    #842778
    Tom
    Lead Developer
    Lead Developer

    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!

    #843498
    Tom
    Lead Developer
    Lead Developer

    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 );
    #843538
    Simon

    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

    #843542
    Tom
    Lead Developer
    Lead Developer

    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.

    #843645
    Simon

    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

    #843921
    Tom
    Lead Developer
    Lead Developer

    Glad I could help! ๐Ÿ™‚

    #1156435
    Simon

    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

    #1156799
    Tom
    Lead Developer
    Lead Developer

    Hi Simon,

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

    #1156964
    Simon

    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

    #1157210
    Tom
    Lead Developer
    Lead Developer

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

    #1157314
    Simon

    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

Viewing 15 posts - 16 through 30 (of 33 total)
  • You must be logged in to reply to this topic.