Ga naar inhoud

Fix "file_get_contents" error

This error is related to the theme.json file and is seen with Sage 9 projects and WordPress 6.3.

Example error

Notice: file_get_contents(): Read of 8192 bytes failed with errno=21 Is a directory in /app/web/wp/wp-includes/functions.php on line 4570
Call Stack:
0.0014 382792 1. {main}() /app/web/index.php:0
// ...
// More lines
// ...
0.2938 16403032 22. file_get_contents($filename = '/app/web/app/themes/theme/resources') /app/web/wp/wp-includes/functions.php:4570
Notice: Error when decoding a JSON file at path /app/web/app/themes/cibv/resources: Syntax error in /app/web/wp/wp-includes/functions.php on line 4578

Fix

To fix this error add the following snippet to your functions.php file.

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

Resources

  1. https://discourse.roots.io/t/sage-9-file-get-contents-warnings-after-update-wp-to-6-3/25800/5