# Keep Only the Theme Fonts You Use

> Removes the font families you do not use from the theme's font list, so editors see a short list and the unused fonts are never loaded.

- Type: PHP
- Runs: Run everywhere
- Category: [Block Editor](https://wpide.com/library/category/gutenberg/)
- Tags: theme-json, fonts, performance
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/themejson-limit-theme-fonts/

## Code

```php
// Font family slugs to keep.
$wpide_keep_font_slugs = array( 'manrope', 'fira-code' );

add_filter( 'wp_theme_json_data_theme', function ( $theme_json ) use ( $wpide_keep_font_slugs ) {
    $data     = $theme_json->get_data();
    $families = isset( $data['settings']['typography']['fontFamilies'] ) ? (array) $data['settings']['typography']['fontFamilies'] : array();
    $families = isset( $families['theme'] ) ? (array) $families['theme'] : $families;

    if ( ! $families ) {
        return $theme_json;
    }

    $kept = array_values( array_filter( $families, function ( $family ) use ( $wpide_keep_font_slugs ) {
        return isset( $family['slug'] ) && in_array( $family['slug'], $wpide_keep_font_slugs, true );
    } ) );

    // Never leave the theme without fonts because of a typo.
    if ( ! $kept ) {
        return $theme_json;
    }

    return $theme_json->update_with( array(
        'version'  => WP_Theme_JSON::LATEST_SCHEMA,
        'settings' => array( 'typography' => array( 'fontFamilies' => $kept ) ),
    ) );
} );
```

## Notes

Font slugs are shown in the theme's theme.json (settings.typography.fontFamilies). Text set to a removed font falls back to the default font.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Keep Only the Theme Fonts You Use" 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/
