Fonts
Which fonts Oxygen registers, and where they load from.
Registration
oxygen_register_font
Filter, $font. Called once per font. Return false to drop it. The classic use is
switching Google Fonts off:
add_filter('oxygen_register_font', function ($font) {
$isGoogleFont = !!$font['dependencies']['googleFonts'];
if ($isGoogleFont) {
return false;
}
return $font;
});
oxygen_register_fonts
Action, $fontsController. The point at which to register fonts of your own. Call
registerFont($slug, $cssName, $label, $fallbackString, $dependencies) on the controller it
passes; $dependencies takes the same styles / scripts shape as an element's, so a
self-hosted face is one stylesheet:
add_action('oxygen_register_fonts', function ($fontsController) {
$fontsController->registerFont(
'my-plugin-inter',
'"Inter"',
'Inter (self-hosted)',
'sans-serif',
['styles' => [plugins_url('fonts/inter.css', __FILE__)]]
);
});
The font then appears in every font dropdown in the builder, and its stylesheet is only
loaded on pages that use it.
oxygen_google_fonts_url
Filter, $googleFontUrl. The full stylesheet URL Oxygen requests the page's Google Fonts
from — https://fonts.googleapis.com/css2?family=…&display=swap, with every family the page
uses already in the query string. Swap the host to serve the same fonts from somewhere else.
A regional mirror is the usual reason. fonts.googleapis.com is unreachable from mainland
China, so a site with visitors there can point at
SJTUG's Google Fonts mirror, a reverse proxy
that answers on the same paths:
add_filter('oxygen_google_fonts_url', function ($url) {
return str_replace(
'fonts.googleapis.com',
'google-fonts.mirrors.sjtug.sjtu.edu.cn',
$url
);
});
The font files the stylesheet links to are served from fonts.gstatic.com, which this
filter doesn't touch. Mirrors that rewrite those references handle it for you; ones that
don't leave the second request pointing at Google.