You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何阻止Divi主题加载Google字体并本地托管优化加载速度

How to Stop Divi from Loading Google Fonts for Local Font Hosting

Hey there! I’ve helped many folks switch to locally hosted Google Fonts with Divi, so let’s break this down step by step to get you sorted.

1. Disable the et_core_load_main_fonts Function (Critical!)

Divi’s core function et_core_load_main_fonts is the main culprit behind loading Google Fonts by default. Never edit the parent theme’s /Divi/core/functions.php directly—theme updates will wipe out your changes. Instead, add this code to your child theme’s functions.php file:

// Disable Divi's default Google Fonts enqueue
add_action( 'wp_enqueue_scripts', 'disable_divi_google_fonts', 100 );
function disable_divi_google_fonts() {
    // Remove the core function that loads Google Fonts
    remove_action( 'wp_enqueue_scripts', 'et_core_load_main_fonts' );
}

The priority 100 ensures this runs after Divi’s original hook, so it properly overrides and removes the font-loading action.

2. Remove Hardcoded Google Fonts from the Site Header

You mentioned your site header has Google Fonts references. Again, skip editing the parent theme’s header.php—use your child theme instead:

  • Copy the parent theme’s header.php file into your child theme folder
  • Open the child theme’s header.php and delete any <link> tags pointing to fonts.googleapis.com
  • Save the file—your child theme will now use this modified header instead of the parent’s.

If the header fonts are added via a hook (not hardcoded), you can find the corresponding action/filter and remove it in your child theme’s functions.php. For example, if it’s hooked to wp_head, you might use:

remove_action( 'wp_head', 'custom_font_enqueue_function' );

Just replace custom_font_enqueue_function with the actual function name adding the font link (check your parent theme’s code or use a hook inspector tool to track it down).

3. Update Divi Customizer Settings

Even after disabling the core function, Divi’s Customizer might still try to load Google Fonts if you have them selected. Head to Divi > Theme Customizer > General > Typography:

  • Set all font dropdowns (Body Font, Heading Font, etc.) to System Font or the exact name of your locally hosted font (e.g., "Roboto" if you’ve hosted it locally)
  • Save your changes—this stops Divi from generating any leftover Google Fonts requests.

4. Verify the Fix

To confirm you’ve blocked all Google Fonts loads:

  1. Open your site in Chrome/Firefox DevTools (press F12)
  2. Go to the Network tab and refresh the page
  3. Search for fonts.googleapis.com—if no requests appear, you’ve successfully stopped Divi from loading Google Fonts!

Now you can proceed to add your locally hosted fonts using @font-face in your child theme’s style.css, or enqueue them via wp_enqueue_style in your child theme’s functions.php.

内容的提问来源于stack exchange,提问作者Steve

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:22:04