# Remove Google Fonts Loaded by Themes and Plugins

> Dequeues every stylesheet loaded from Google Fonts and removes the related preconnect hints, for speed and GDPR compliance.

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

## Code

```php
$wpide_drop_google_fonts = function () {
    $styles = wp_styles();

    foreach ( $styles->registered as $handle => $style ) {
        if ( is_string( $style->src ) && false !== strpos( $style->src, 'fonts.googleapis.com' ) ) {
            wp_dequeue_style( $handle );
            wp_deregister_style( $handle );
        }
    }
};

add_action( 'wp_enqueue_scripts', $wpide_drop_google_fonts, 999 );
add_action( 'wp_print_styles', $wpide_drop_google_fonts, 1 );

add_filter( 'wp_resource_hints', function ( $urls ) {
    return array_values( array_filter( $urls, function ( $url ) {
        $href = is_array( $url ) ? ( isset( $url['href'] ) ? $url['href'] : '' ) : $url;

        return false === strpos( (string) $href, 'fonts.googleapis.com' ) && false === strpos( (string) $href, 'fonts.gstatic.com' );
    } ) );
}, 99 );
```

## Notes

Your theme falls back to system fonts unless you host the fonts yourself, and page builders that inline fonts need their own setting.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Remove Google Fonts Loaded by Themes and Plugins" 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/
