Failed to open stream No such file or directory : Wordpress custom function with yaml_parse_file

I'm trying to learn how to extract data from a yaml file inside of a custom Wordpress theme.

functions.php :

function require_plugins(){
   $yaml_data = yaml_parse_file(get_template_directory_uri() . '/pluginsInfo.yml',);
   var_dump($yaml_data);
};

But all I have is :

PHP Warning:  yaml_parse_file(http://wordpress2.local/wp-content/themes/new_theme/pluginsInfo.yml): failed to open stream: No such file or directory in /var/www/wordpress/wp-content/themes/new_theme/functions.php on line 191

my folder

Where is my error please ?

1 answer

  • answered 2021-06-18 23:20 flyx

    yaml_parse_file takes a path, not an URI. So you should do

    $yaml_data = yaml_parse_file(get_template_directory() . '/pluginsInfo.yml');