Wordpress - no such file or directory issue

2019-03-04 18:51发布

I am getting this error when I load up my Wordpress site:

Warning: include_once(../../plugins/acf-location-field-master/acf-location.php) [function.include-once]: failed to open stream: No such file or directory in C:\wamp\www\cmpmushrooms.tld\wp-content\themes\shrooms_v0.1\functions.php on line 455

The code it is referring to is this:

function my_register_fields()
{
    include_once('../../plugins/acf-location-field-master/acf-location.php');
}

I realise it is saying it cannot find the file but why is that? because it exists in the directory.

标签: php wordpress
2条回答
放我归山
2楼-- · 2019-03-04 19:40

Why not:

include_once ( WP_PLUGIN_DIR . '/acf-location-field-master/acf-location.php');
查看更多
时光不老,我们不散
3楼-- · 2019-03-04 19:41

You should do this way to include file from WP plugins directory :

include( plugin_dir_path( __FILE__ ) . 'plugin-name/file-name.php');

If you want to include all files within that directory, use it like this:

foreach ( glob( plugin_dir_path( __FILE__ )."plugin-name/*.php" ) as $file )
    include_once $file;

Have fun :)

查看更多
登录 后发表回答