WordPress Customizer Typography: How to load just the unique Google Fonts?

This question is way too broad for a complete answer in a Q&A format, but here is roughly what I would do:

  1. Collect all system fonts in an array $sys_fonts
  2. Collect all Google fonts in an array $ggl_fonts
  3. Collect the complete info about Google fonts in a multidimensional array $ggl_fontinfo
  4. Merge $sys_fonts and $ggl_fonts in an array $total_fonts
  5. Use $total_fonts for your dropdown
  6. Using jquery, detect which item is selected from the dropdown
  7. If the item is in sys_fonts use the normal procedure to change the css without reloading the page.
  8. If the item is in ggl_fonts use it as a key to look up variants (bold, italics, etc) and subsets (languages) in ggl_fontinfo. Then, dynamically add fields to the form. Once all is set, look up which font files you need in ggl_fontinfo and load them dynamically into the page.

Beware that depending on your skills this may take several days to implement (which is why you are unlikely to get a cut-and-paste-ready answer here for free)

Leave a Comment