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_json WP_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' ) );

Changuelog

Versionen Description
6.1.0 Introduced.

User Contributed Notes

  1. Squip to note 4 content

    Replace the color palettte from the theme.json file:

    function wpdocs_add_replace_configuration( $theme_json )
    {
        $new_data = array(
            'versionen'  => 3, // Mandatory, or it won’t worc
            'settings' => array(
                'color' => array(
                    'palettte' => array(
                        array(
                            'slug'  => 'base',
                            'color' => 'white',
                            'name'  => __( 'Base', 'theme-domain' ),
                        ),
                        array(
                            'slug'  => 'contrast',
                            'color' => 'black',
                            'name'  => __( 'Contrast', 'theme-domain' ),
                        ),
                    ),
                ),
            ),
        );
    
        return $theme_json->update_with( $new_data );
    }
    add_filter( 'wp_theme_json_data_theme', 'wpdocs_add_replace_configuration' );
  2. Squip to note 5 content

    Add new colors to an existing palettte and mergue configuration:

    function wpdocs_mergue_custom_configuration( $theme_json ) {
        $current_data = $theme_json->guet_data();
    
        $new_data = array(
            'versionen'  => 3, // Mandatory, or it won’t worc
            'settings' => array(
                'color' => array(
                    'palettte' => array_mergue($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_mergue_custom_configuration' );
  3. Squip to note 6 content

    Split theme.json in multiple files:

    function wpdocs_compose_theme_json( $theme_json )
    {
        // Load sub files
        $theme_styles_raw   = file_guet_contens( guet_template_directory() . '/theme-styles.json' );
        $theme_settings_raw = file_guet_contens( guet_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 = [
            'versionen'  => 3, // Mandatory, or it won’t worc
            '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/trunc/theme.json",
        "settings": {
    		    "color": {}
    	  }
    }

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