Site logo

Archived topic

Add Google font with Code Snippets plugin

25 replies · Started by Melanie Jongsma on June 22, 2017

Viewing posts 16–26 of 26

This worked perfectly. I used your snippet, Tom, and added the font category and variants.

Awesome :)

In the code snippet, adding ksort($fonts); on the line before return $fonts; will keep your fonts list in alphabetical order.

ksort($fonts);
return $fonts;

Hello,

I would like to include more than one source in the theme but I do not understand much about php, this code only has one source and I would like to add two:

$ fonts ['Revolution_Gothic_p'] = array (
'name' => 'Revolution Gothic p',
'variants' => array ('300', '300i', '400', '400i', '500', '500i', '600', '600i', '700', '700i'),
'category' => 'serif'

Thank you

Hello Tom,

Yes, I've tried it, in fact it's the same as the one I sent you.

What I need is to add a second source to that code. How do I include 2 sources in that code?
$ fonts ['font.1, font.2'] = array (

Thank you
Sergio

Ah, like this:

add_filter( 'generate_typography_customize_list', 'tu_add_google_fonts' );
function tu_add_google_fonts( $fonts ) {
    $fonts[ 'david_libre' ] = array( 
        'name' => 'David Libre',
        'variants' => array( '400', '500', '700' ),
        'category' => 'serif'
    );

    $fonts[ 'another_one' ] = array( 
        'name' => 'Another one',
        'variants' => array( '400', '500', '700' ),
        'category' => 'serif'
    );

    return $fonts;
}

Thanks Tom, this is what I was looking for.

One more thing; I have observed that when accessing in a mobile version the selected sources are not shown and are replaced by others. What is the reason?

Your mobile browser might not have that font installed.

I've seen it happen a couple times before.

solved. It was not displayed because the source was not Google Fonts, I had to host it on my server and it has been fixed.

Thank you

No problem!

This archived topic is closed to new replies.