# Problems with theme.json on Sage 9 after WP update to 6.3

**URL:** https://discourse.roots.io/t/problems-with-theme-json-on-sage-9-after-wp-update-to-6-3/25856
**Category:** sage
**Tags:** sage9
**Created:** 2023-08-24T09:43:46Z
**Posts:** 6

## Post 1 by @cabans — 2023-08-24T09:43:46Z

I have few old sites that we have with Sage 9, and after update to WordPress 6.3 all the settings and parameter in theme.json has disappear from the editor.

Did you know if there is any hook to force to load correctly theme.json in this case?  
I’ve been reading some topics related but no one gave me a possible way, and now I have a problem with 2 of these sites that use colors and spacing a lot.

Someone had same problems?

Thanks in advance!

---

## Post 2 by @cabans — 2023-08-24T10:44:48Z

After some research, digging into the WordPress code in one of the classes it uses for the theme.json I managed to find and use the `wp_theme_json_data_theme` hook that allows you to update the data passed to WP from the theme’s own json file.

Maybe not the perfect solution, but it works as a workaround, here is the code if anyone needs it:

```
add_filter( 'wp_theme_json_data_theme', function( $theme_json ){
    // Set path to theme.json file
    $json_file = get_stylesheet_directory() . '/theme.json';

    // Check if file exists
    if( !file_exists( $json_file ) ) {
        return $theme_json;
    }

    // Load theme.json file from theme root in $new_data
    $new_data = json_decode( file_get_contents( $json_file ), true );

	return $theme_json->update_with( $new_data );
} );
```

If you know a better solution, let me know :slight_smile:

---

## Post 3 by @Anthony_Simonelli — 2023-09-01T20:29:55Z

The issue I’m experiencing is when the `wp_get_global_stylesheet()` function is called in [global-styles-and-settings.php](https://core.trac.wordpress.org/browser/trunk/src/wp-includes/global-styles-and-settings.php#L182), I receive an error despite having the `theme.json` file in the correct location of the theme:

```
Notice: Error when decoding a JSON file at path /app/web/app/themes/wordpress-theme/resources: Syntax error in /app/web/wp/wp-includes/functions.php on line 4578
```

This is because when it calls `get_theme_data()` in [class-wp-theme-json-resolver.php](https://core.trac.wordpress.org/browser/trunk/src/wp-includes/class-wp-theme-json-resolver.php#L243) it is setting the `$theme_json_file` to the directory, with the file name. This is because the [get\_file\_path](https://developer.wordpress.org/reference/classes/wp_theme/get_file_path/) method of WP\_Theme has a filter that applies the _dirname_ filter.

And the `is_readable()` function evaluates to _true_ because the directory exists. Then the JSON decode fails, resulting in the above notice. I don’t understand why `file_exists` wasn’t used instead.

Does anyone know of a way to adjust the theme so that this notice doesn’t occur, filling log files?

---

## Post 4 by @Twansparant — 2023-09-13T07:38:14Z

Yeah this is weird one!  
Having the same error indeed on **Sage 9** themes after updating to **WP 6.3** and I am not even using a `theme.json` file in the resources folder?

---

## Post 5 by @ben — 2023-09-13T15:42:09Z

There’s some additional discussion here: [Sage 9 + Wordpress 6.3 : Notice: Error when decoding a JSON file at path... · Issue #3143 · roots/sage · GitHub](https://github.com/roots/sage/issues/3143)

---

## Post 6 by @joshb — 2023-09-13T17:13:27Z

Adding this snippet to `filters.php` was the solution that worked best for me on an old project I updated to latest WP core, etc…

```
add_filter('theme_file_path', function($path, $file) {
    if($file === 'theme.json') {
        return false;
    }
    return $path;
}, 0, 2);
```
