Archived topic
generate_typography_customize_list
11 replies · Started by NBC on May 20, 2018
I'm attempting to use the generate_typography_customize_list function to add the three parts of the Barlow family from Google Fonts to the Customizer's font list.
I'm following the instructions here.
I've added the relevant code to my child theme's functions.php file. The typefaces do not show up in the Customizer, however.
I'm developing this site under localhost, so no site link to share.
Here's the code.
add_filter( 'generate_typography_customize_list', 'tu_add_google_fonts' );
function tu_add_google_fonts( $fonts ) {
$fonts[ 'Barlow' ] = array(
'name' => 'Barlow',
'variants' => array('100', '100i', '200', '200i', '300', '300i', '400', '400i', '500', '500i', '600', '600i', '700', '700i', '800', '800i', '900', '900i' ),
'category' => 'sans-serif'
);
$fonts[ 'Barlow Semi Condensed' ] = array(
'name' => 'Barlow Semi Condensed',
'variants' => array('100', '100i', '200', '200i', '300', '300i', '400', '400i', '500', '500i', '600', '600i', '700', '700i', '800', '800i', '900', '900i' ),
'category' => 'sans-serif'
);
$fonts[ 'Barlow Condensed' ] = array(
'name' => 'Barlow Condensed',
'variants' => array('100', '100i', '200', '200i', '300', '300i', '400', '400i', '500', '500i', '600', '600i', '700', '700i', '800', '800i', '900', '900i' ),
'category' => 'sans-serif'
);
return $fonts;
}
Hi there,
I copied and paste your code in Code Snippets and it worked for me.
Did you check at the bottom of the list and or use the search?
Let me know.
Hi, Leo:
I searched for other discussion threads that covered this topic, as well as the documentation itself. The solution I implemented comes straight out of the GP documentation. Added to the functions.php file of my child theme, the code has no impact whatsoever.
There is a bit of misunderstanding :)
I meant search in the customizer typography list.
I did test your code and it worked for me:
http://www.screencast.com/t/09GNNU2Y
Hi, Leo:
I tried the Code Snippets plug-in. Turns out it adds the typefaces to the end of the list. I was looking for them to appear alphabetized in with the rest of the list.
However, the style list does not appear. All three Barlow typeface families include 9 weights. The Font Family list of styles does not appear in the Customizer. I can select normal and (what looks like a fake) bold, but that's it.
Can you try this instead?:
add_filter( 'generate_typography_customize_list', 'tu_add_google_fonts' );
function tu_add_google_fonts( $fonts ) {
$fonts[ 'barlow' ] = array(
'name' => 'Barlow',
'variants' => array('100', '100i', '200', '200i', '300', '300i', '400', '400i', '500', '500i', '600', '600i', '700', '700i', '800', '800i', '900', '900i' ),
'category' => 'sans-serif'
);
$fonts[ 'barlow_semi_condensed' ] = array(
'name' => 'Barlow Semi Condensed',
'variants' => array('100', '100i', '200', '200i', '300', '300i', '400', '400i', '500', '500i', '600', '600i', '700', '700i', '800', '800i', '900', '900i' ),
'category' => 'sans-serif'
);
$fonts[ 'barlow_condensed' ] = array(
'name' => 'Barlow Condensed',
'variants' => array('100', '100i', '200', '200i', '300', '300i', '400', '400i', '500', '500i', '600', '600i', '700', '700i', '800', '800i', '900', '900i' ),
'category' => 'sans-serif'
);
return $fonts;
}
Let me know :)
Hi, Tom:
Yes, that did the trick. I'd love to know why!
Thanks for the invaluable assistance!
The first instance of the names need to be lowercase and separated by underscores.
Glad I could help! :)
Thanks, Tom! I learn something every day.
You're welcome! :)
Hi Tom, is the 'generate_typography_customize_list' function still the most up-to-date way to add Google fonts programatically? Thanks
Hi David,
i passed your other support topic over to Tom to take a look.