Elementor 开发者文档

title: "Font Display" post_status: publish comment_status: open taxonomy: category: - elementor-developers-docs post_tag: - Hooks - Src - Repos


Font Display

Elementor offers a filter hook that lets developers overwrite the "Custom Fonts" font-display value. In other words, you can control how font files are loaded and displayed by the browser.

Hook Details

Font Display

The CSS font-display property defines how font files are loaded and displayed by the browser and can be set with one of the following values:

Applying Font Display

Google Fonts

It is possible to set the font-display value for "Google Fonts" from the WordPress admin. Simply go to ElementorSettingsAdvancedGoogle Fonts Load.

Custom Fonts

In order to overwrite the font-display value for "Custom Fonts", the following actions should be applied:

Add the following filter in the Elementor Pro plugin folder:

/**
 * Control how font files are loaded and displayed by the browser.
 * Set the `font-display` property to `swap`.
 *
 * @since 1.0.0
 */
function update_font_display() {

    return 'swap'; // Or any other value.

}
add_filter( 'elementor_pro/custom_fonts/font_display', 'update_font_display' );

To regenerate CSS files from the admin (the value will be changed only after regenerating, go to ElementorToolsGeneralRegenerate CSS.