- This topic has 11 replies, 2 voices, and was last updated 3 months, 1 week ago by
David.
-
AuthorPosts
-
May 20, 2018 at 7:20 pm #580410
NBC
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; }
May 20, 2018 at 8:17 pm #580431Leo
StaffCustomer SupportHi 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.
May 21, 2018 at 1:35 pm #581113NBC
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.
May 21, 2018 at 1:42 pm #581118Leo
StaffCustomer SupportThere 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/09GNNU2YMay 21, 2018 at 2:52 pm #581155NBC
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.
May 21, 2018 at 9:06 pm #581337Tom
Lead DeveloperLead DeveloperCan 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 π
May 21, 2018 at 9:25 pm #581352NBC
Hi, Tom:
Yes, that did the trick. I’d love to know why!
Thanks for the invaluable assistance!
May 21, 2018 at 9:27 pm #581353Tom
Lead DeveloperLead DeveloperThe first instance of the names need to be lowercase and separated by underscores.
Glad I could help! π
May 22, 2018 at 1:20 am #581432NBC
Thanks, Tom! I learn something every day.
May 22, 2018 at 7:48 am #581708Tom
Lead DeveloperLead DeveloperYou’re welcome! π
February 23, 2023 at 10:08 am #2544355David
Hi Tom, is the ‘generate_typography_customize_list’ function still the most up-to-date way to add Google fonts programatically? Thanks
February 24, 2023 at 2:02 am #2545113David
StaffCustomer SupportHi David,
i passed your other support topic over to Tom to take a look.
-
AuthorPosts
- You must be logged in to reply to this topic.