如何阻止Divi主题加载Google字体并本地托管优化加载速度
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.phpfile into your child theme folder - Open the child theme’s
header.phpand delete any<link>tags pointing tofonts.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:
- Open your site in Chrome/Firefox DevTools (press F12)
- Go to the Network tab and refresh the page
- 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

