Without the Plugin

Yabe Webfont offers unlimited site activations on all pricing plans. We have prepared this guide if you want to keep the custom fonts when you disable or uninstall the plugin for some reason.

Use the following code snippet with your theme’s functions.php file or snippet plugin to load the fonts file and preload the fonts on the front page.

You can also set the YWFDOCS_INLINE_CSS constant to true to load the CSS file as inline instead of a file.

<?php

/**
 * Load CSS file as inline instead of file?
 * 
 * @var bool
 */
const YWFDOCS_INLINE_CSS = false;

/**
 * Preload the fonts file and load the CSS file on the front page.
 */
add_action('wp_head', function (): void {
    $cache_path = wp_upload_dir()['basedir'] ;
    $cache_url = wp_upload_dir()['baseurl'];

    if (file_exists("{$cache_path}/yabe-webfont/cache/preload.html")) {
        $preload_html = file_get_contents("{$cache_path}/yabe-webfont/cache/preload.html");
        if ($preload_html !== false) {
            echo $preload_html;
        }
    }
    
    if (file_exists("{$cache_path}/yabe-webfont/cache/fonts.css")) {
        if (YWFDOCS_INLINE_CSS) {
            $css = file_get_contents("{$cache_path}/yabe-webfont/cache/fonts.css");
            if ($css !== false) {
                echo sprintf("<style id=\"%s-css\">\n%s\n</style>", 'yabe_webfont-cache', $css);
            }
        } else {
            wp_register_style('yabe_webfont-cache', "{$cache_url}/yabe-webfont/cache/fonts.css");
            wp_print_styles('yabe_webfont-cache');
        }
    }
});

Copied!