Site logo

Archived topic

Load additional Google Font without specifying in Customiser

3 replies · Started by Alex on March 31, 2020

Viewing posts 1–4 of 4

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

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.

Thanks Tom, that works perfectly :)

Glad I could help :)

This archived topic is closed to new replies.