如何阻止Divi主题加载Google字体

时间:2018-02-14 作者:Steve

我想在本地托管谷歌字体,希望能减少一些页面加载时间。

我希望使用google-webfonts-helper 这样做。

我需要确保我们的主题Divi不会加载原始的Google字体。

目前,我们的网站主要有以下内容。

<link data-asynced=\'1\' as=\'style\' onload=\'this.rel="stylesheet"\'  rel=\'preload\' id=\'divi-fonts-css\'  href=\'https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800&#038;subset=latin,latin-ext\' type=\'text/css\' media=\'all\' />
在中/Divi/core/functions.php, 有:

if ( ! function_exists( \'et_core_get_main_fonts\' ) ) :
function et_core_get_main_fonts() {
    global $wp_version;

    if ( version_compare( $wp_version, \'4.6\', \'<\' ) ) {
        return \'\';
    }

    $fonts_url = \'\';

    /* Translators: If there are characters in your language that are not
     * supported by Open Sans, translate this to \'off\'. Do not translate
     * into your own language.
     */
    $open_sans = _x( \'on\', \'Open Sans font: on or off\', \'Divi\' );

    if ( \'off\' !== $open_sans ) {
        $font_families = array();

        if ( \'off\' !== $open_sans )
            $font_families[] = \'Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800\';

        $protocol = is_ssl() ? \'https\' : \'http\';
        $query_args = array(
            \'family\' => implode( \'%7C\', $font_families ),
            \'subset\' => \'latin,latin-ext\',
        );
        $fonts_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" );
    }

    return $fonts_url;
}
endif;

if ( ! function_exists( \'et_core_load_main_fonts\' ) ) :
function et_core_load_main_fonts() {
    $fonts_url = et_core_get_main_fonts();
    if ( empty( $fonts_url ) ) {
        return;
    }

    wp_enqueue_style( \'et-core-main-fonts\', esc_url_raw( $fonts_url ), array(), null );
}
endif;
如何阻止Divi主题加载Google字体?

是否需要禁用该功能et_core_load_main_fonts ?

感谢您的帮助。

2 个回复
最合适的回答,由SO网友:Steve 整理而成

看来有人已经做了我需要做的事。

从…起this post, 我可以将以下代码添加到我的子主题functions.php:

// REMOVE OPEN SANS GOOGLE FONT FROM DIVI
function disable_open_sans_divi() {
wp_dequeue_style( \'divi-fonts\' );
}
add_action( \'wp_enqueue_scripts\', \'disable_open_sans_divi\', 20 );

SO网友:Maxim Sarandi

wp_dequeue_style() 应该对你有帮助。您应该将样式和字体排成队列。

wp_dequeue_style(\'et-core-main-fonts\');
wp_enqueue_style(\'your_fonts_handle\', \'path_to_your_fonts\');
或使用字体重新声明功能。

et_core_load_main_fonts() {
    $fonts_url = et_core_get_main_fonts();
    if ( empty( $fonts_url ) ) {
        return;
    }

    wp_enqueue_style( \'et-core-main-fonts\', esc_url_raw( \'path_to_your_style\' ), array(), null );
}

结束

相关推荐

Using True Type Fonts (ttf)

我在网上找到了一些不错的True Type字体,我想在我的WP博客的特定主题中使用它们来扮演特定角色(例如。,H2 或帖子标题)。如何更改主题以使用这些角色的字体?