apply_filters( ‘wp_theme_json_data_theme’, WP_Theme_JSON_Data $theme_json )

Filters the data provided by the theme for global styles and settings.

Parameters

$theme_jsonWP_Theme_JSON_Data
Class to access and update the underlying data.

Source

$theme_json = apply_filters( 'wp_theme_json_data_theme', new WP_Theme_JSON_Data( $theme_json_data, 'theme' ) );

Changelog

VersionDescription
6.1.0Introduced.

User Contributed Notes

  1. Skip to note 3 content

    Add new colors to an existing palette and merge configuration:

    function wpdocs_merge_custom_configuration( $theme_json ) {
        $current_data = $theme_json->get_data();
    
        $new_data = array(
            'version'  => 3, // Mandatory, or it won’t work
            'settings' => array(
                'color' => array(
                    'palette' => array_merge($current_data[‘settings’][‘color’][‘palette’][‘theme’], array(
                        array(
                            'slug'  => 'base',
                            'color' => 'white',
                            'name'  => __( 'Base', 'textdomain' ),
                        ),
                        array(
                            'slug'  => 'contrast',
                            'color' => 'black',
                            'name'  => __( 'Contrast', 'textdomain' ),
                        ),
                    )),
                ),
            ),
        );
    
        return $theme_json->update_with( $new_data );
    }
    add_filter( 'wp_theme_json_data_theme', 'wpdocs_merge_custom_configuration' );
  2. Skip to note 4 content

    Split theme.json in multiple files:

    function wpdocs_compose_theme_json( $theme_json )
    {
        // Load sub files
        $theme_styles_raw   = file_get_contents( get_template_directory() . '/theme-styles.json' );
        $theme_settings_raw = file_get_contents( get_template_directory() . '/theme-settings.json' );
    
        // Convert JSON to array
        $theme_styles   = json_decode( $theme_styles_raw, true );
        $theme_settings = json_decode( $theme_settings_raw, true );
    
        // Inject data
        $new_data = [
            'version'  => 3, // Mandatory, or it won’t work
            'settings' => $theme_settings['settings'],
            'styles'   => $theme_styles['styles'],
        ];
    
        // Update WordPress' theme.json
        return $theme_json->update_with( $new_data );
    }
    add_filter( 'wp_theme_json_data_theme', 'wpdocs_compose_theme_json' );

    In theme-settings.json:

    {
        "$schema": "https://schemas.wp.org/trunk/theme.json",
        "settings": {
    		    "color": {}
    	  }
    }

You must log in before being able to contribute a note or feedback.