# Show Text Immediately While Google Fonts Load

> Adds display=swap to every Google Fonts stylesheet your theme and plugins load, so text appears right away in a fallback font instead of staying invisible while the web font downloads.

- Type: PHP
- Runs: Frontend only
- Category: [Performance](https://wpide.com/library/category/performance/)
- Tags: google-fonts, fonts, core-web-vitals
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/perf-google-fonts-display-swap/

## Code

```php
add_filter( 'style_loader_src', function ( $src ) {
    if ( ! is_string( $src ) || false === strpos( $src, 'fonts.googleapis.com' ) || false !== strpos( $src, 'display=' ) ) {
        return $src;
    }

    return $src . ( false === strpos( $src, '?' ) ? '?' : '&' ) . 'display=swap';
}, 20 );
```

## Notes

URLs that already set a display value are left alone.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Show Text Immediately While Google Fonts Load" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
