Page MenuHomeGitPull.it

Remove Google Font external dependency
Closed, ResolvedPublic

Event Timeline

Added this plugin:

<?php
/**
Plugin Name: Valerio Self-hosting a Google Font
Description: Host on your own server your Google Font for privacy reasons.
Version: 1.0.0.0.0
Author: Valerio Bozzolan
Author URI: https://boz.reyboz.it/
License: GPLv3+
*/
function valerio_google_font_self_hosted_asd() {
        $style = 'twentyseventeen-fonts';

        if( wp_style_is($style, 'enqueued') ) {
                wp_deregister_style($style);
                wp_enqueue_style($style, plugin_dir_url(__FILE__) . 'libre-franklin.css', array(), 'asd');
                wp_enqueue_style($style);
        }
        return true;
}

function valerio_google_font_self_hosted_asd_asd() { ?>
        <div class="updated">
                <p>Cosa stai facendo? Cambi tema? L'hai detto a Valerio?</p>
        </div>
<?php
}

function valerio_google_font_self_hosted_warning() {
        add_action('admin_notices', 'valerio_google_font_self_hosted_asd_asd');
}

add_filter('wp_enqueue_scripts', 'valerio_google_font_self_hosted_asd', 11);
add_filter('switch_theme',       'valerio_google_font_self_hosted_warning');

// fixes /themes/twentyseventeen/functions.php
add_filter( 'wp_resource_hints', function( $urls, $relation_type ) {
        foreach( $urls as $i => $url ) {
                if( isset( $url['href'] ) && $url['href'] === 'https://fonts.gstatic.com' ) {
                        unset( $urls[$i] );
                }
        }
        return $urls;
}, 11, 2 );