Fixing 'Ensure Text Remains Visible During Webfont Load' Warnings with Custom Fonts
Content
If you're using the 'Custom Fonts – Host Your Fonts Locally' plugin and Google PageSpeed Insights is flagging a warning about ensuring text remains visible during webfont load, you're not alone. This is a common performance recommendation related to how browsers load and display custom fonts. Let's break down what this means and how to fix it.
Understanding the 'Font Display' Warning
This warning appears when a browser doesn't have specific instructions on how to handle text while your custom font is loading. Without these instructions, the browser might hide the text until the font is fully downloaded (a behavior known as a 'flash of invisible text' or FOIT). Google recommends using font-display: swap to tell the browser to display text immediately using a fallback system font, and then 'swap' in the custom font once it has loaded. This creates a better user experience.
How to Apply font-display: swap
The 'Custom Fonts – Host Your Fonts Locally' plugin includes a built-in setting to manage this. Here’s how to configure it:
- In your WordPress admin, navigate to Custom Fonts.
- Edit the custom font that is causing the warning.
- Scroll down to the Advanced section.
- Locate the Font Display dropdown menu.
- Select Swap from the list of options.
- Save your changes.
After changing this setting, you may need to clear your site's cache and any server-level cache for the changes to take effect. Some users have reported that after changing this setting, they also needed to regenerate CSS in their page builder (like Elementor) for the warning to disappear from PageSpeed tests.
What If the Setting Doesn't Seem to Work?
Some users have found that selecting 'Swap' does not immediately resolve the warning, while selecting 'Preload' does. This could be due to caching or how the theme or page builder processes the CSS. If you encounter this, try the following:
- Clear all caching layers: browser cache, WordPress cache plugin, and server cache (if applicable).
- Ensure your theme or page builder is one that is compatible with the plugin, as noted in its description. Incompatibility can sometimes cause settings not to apply correctly.
- Double-check that the change was saved correctly by revisiting the font's settings page.
Alternative: Manual Code Snippet
For advanced users, or if the dropdown setting is unavailable due to a bug, you can apply the swap behavior manually with a code snippet. The 'Custom Fonts – Host Your Fonts Locally' team suggests using a filter. Add the following code to your child theme's functions.php file or a code snippets plugin:
add_filter( 'bsf_custom_fonts_font_display', function( $current_value, $font_family, $data ) {
return 'swap';
}, 10, 3 );
Warning: Only edit code if you are comfortable doing so and always back up your site first.
Conclusion
The 'Ensure text remains visible' warning is a common SEO and performance check. By using the Font Display setting in the Custom Fonts plugin to apply 'swap', you can often resolve it quickly. If one method doesn't work, try another or check for conflicts with your theme or caching setup.
Related Support Threads Support
-
fonts not working since updatehttps://wordpress.org/support/topic/fonts-not-working-since-update/
-
Font Display: Swap not workinghttps://wordpress.org/support/topic/font-display-swap-not-working-3/
-
Plesa, force HTTPS and avoid unnecessary support.https://wordpress.org/support/topic/plesa-force-https-and-avoid-unnecessary-support/
-
Ensure text remains visible during webfont loadhttps://wordpress.org/support/topic/ensure-text-remains-visible-during-webfont-load-41/
-
Ensure text remains visible during webfont loadhttps://wordpress.org/support/topic/ensure-text-remains-visible-during-webfont-load-30/
-
SSL issuehttps://wordpress.org/support/topic/ssl-issue-30/
-
Error when changing “Font display”https://wordpress.org/support/topic/error-when-changing-font-display/
-
Add font display property swaphttps://wordpress.org/support/topic/add-font-display-property-swap/
-
Font doesn’t show over HTTPShttps://wordpress.org/support/topic/font-doesnt-show-over-https/
-
Plus Symbol on ‘Add’ button doesn’t register clickhttps://wordpress.org/support/topic/plus-symbol-on-add-button-doesnt-register-click/
-
https by default?https://wordpress.org/support/topic/https-by-default-2/