WordPress Integration

WordPress Integration

Rubix Cube with WordPress Logo

While you certainly do not have to run a WordPress powered site to use the TrippyID Font service, I expect that is where it will primarily be used.

Currently integrating font servers other than Google Fonts into WordPress is a little bit tricky. Hopefully it will easier in the future.

Class Installation

I created a PHP class called AWMFontBuilder that creates a Google Fonts API compatible web font CSS string. Unless the theme you are using chooses to include the class in their theme, and currently none do that I am aware of, you must install this class yourself.

For themes and plugins to be able to use the class, it needs to either be loaded before the theme or plugin calls it or it needs to be loadable with an autoloader.

Unfortunately WordPress is a little behind the times and does not have a class autoloader, so first that needs to be taken care of.

Follow the instructions at my WordPress Plugins page for installing a PSR-4 autoloader and the PHP classes I have for WordPress. Unfortunately it does require use of the command line.

Once that is done, your WordPress install now has the ability to use Google Fonts or any font server you choose that understands the Google Fonts API. Your theme however will likely need to be patched to make use of the class.

Theme Patching

Themes that use Google Fonts have fonts.googleapis.com hard-coded into them. Patching them to use the AWMFontBuilder class is usually pretty straight-forward, usually only the functions.php file needs minor patching. Here is a link to the patch needed to fix the Twenty Seventeen theme: https://github.com/AliceWonderMiscreations/FlossWoff2/blob/master/wordpress/twentyseventeen.diff

As you can see, all the patch does is conditionally define a new function that uses the AWMFontBuilder class, and then conditionally uses that function if it is defined instead of the original function.

If you remove the AWMFontBuilder class or if you remove the PSR-4 autoloader, the theme still continues to work the old way.

Even though I am working to add patches for various themes, statistically speaking the odds are high that I do not have a patch for the theme you use. As long as it is a theme I have legal access to (e.g. a free theme, or a commercial theme the developer is willing to give me temporary access to) I can probably create the patch for you.

To apply the patch, simply copy the diff file into your theme directory (might want to back it up first) and then run the command

patch -p1 < themename.diff

My experience is that sometimes WordPress caching gets in the way, so it is a good idea to switch to a different them before applying the patch and then switch back. That seems to avoid the cache issue.

Yes, patching a theme is something that many people simply will want to do. Hopefully I can convince some theme developers to include the AWMFontBuilder class in their theme so that people will not have to.

Define Your Font Mirror

Once the AWMFontBuilder class is installed and your theme is patched to use it, your theme will still use fonts.googleapis.com by default for its web font source.

To switch to a different font server that is compatible with the Google Fonts API, just add a definition to your wp-config.php file:

define('WEBFONT_MIRROR', 'fonts.trippyid.com');

With that constant defined, the AWMFontBuilder class will use your defined mirror instead of fonts.googleapis.com.

Bandwidth Costs

Please note that to use the fonts.trippyid.com font server, I do ask that you help with the bandwidth costs. $60 a year for a domain, $75 for two domains, $100 for up to five domains.

Contact me if you need a font mirror for more than five.

$60 a year is only $5 a month, I do not believe that is too much to ask, especially since the software that makes it happen I am giving away for free under the MIT license:


You can run your own font server using my code for free. I would appreciate financial contributions for my coding effort, but the software is MIT License which means you can stiff me for it if you want. You can even use my software to create a competing font server service you profit from.

Please note the software does check the HTTP Referer header, so the fonts.trippyid.com font server will not work unless I white list the domain that wants to use it. My software is free for you to use without compensation, my bandwidth isn’t.

Leave a Reply

Your email address will not be published. Required fields are marked *

Anonymity protected with AWM Pluggable Unplugged