1

I want to host Google fonts locally to hopefully shave some page loading time off.

I hope to use google-webfonts-helper to do this.

I would need to ensure our theme, Divi, does not load the original Google fonts.

Currently, our site has the following in the head.

<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' />

In /Divi/core/functions.php, there is:

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;

How would I stop the Divi theme from loading the Google font?

Do I need to disable the function et_core_load_main_fonts ?

Help appreciated.

closed as off-topic by Jacob Peattie, EAMann Feb 15 '18 at 23:37

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Are you using a child theme? – Jacob Peattie Feb 14 '18 at 8:16
  • Yes I am using a child theme Jacob – Steve Feb 14 '18 at 8:42
2

wp_dequeue_style() should help you. You should dequeue style and enqueue your fonts.

wp_dequeue_style('et-core-main-fonts');
wp_enqueue_style('your_fonts_handle', 'path_to_your_fonts');

Or redeclare function with 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 );
}
1

Looks like someone has already done what I need to do.

From this post, I can add the following code to my child theme's 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 );
  • You need to change divi-fonts to et-core-main-fonts, since that's the name of the style being added from your code that you said you wanted removed. – Jacob Peattie Feb 14 '18 at 9:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.