[Resolved] Load additional Google Font without specifying in Customiser

Home Forums Support [Resolved] Load additional Google Font without specifying in Customiser

Home Forums Support Load additional Google Font without specifying in Customiser

  • This topic has 3 replies, 2 voices, and was last updated 4 years ago by Tom.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1221411
    Alex

    Hey,
    I’d like to use a Google Font for elements with a specific class. This isn’t difficult on it’s own, but I’d like to load in the font in the same call as the other Google Fonts that are specified in the Customiser. Is there any non-hacky way to do this, I’d rather not apply it to an element that isn’t used, like the h6 tag, to force it to load in.

    Cheers,
    Alex

    #1221559
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    There is a filter, but it filters the string which is a little silly.

    Here’s what you would do:

    add_filter( 'generate_typography_google_fonts', function( $fonts ) {
        $custom_fonts = 'Your+Font+Name:200,300,400';
    
        if ( $fonts ) {
            $custom_fonts = '|' . $custom_fonts;
        }
    
        return $fonts . $custom_fonts;
    } );

    I’ve made a note to add a filter to the array to make it cleaner.

    #1222543
    Alex

    Thanks Tom, that works perfectly ๐Ÿ™‚

    #1222591
    Tom
    Lead Developer
    Lead Developer

    Glad I could help ๐Ÿ™‚

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.