I am new in wordpress development. Tried include a selfwritten php-file into htdocs/wp-content/plugins/abc/abc.php
IDE sugesting me to use: require_once '../WPNonce/WPNonce.php';
but WordPress contradicts when opening in webbrowser:
Fatal error: require_once(): Failed opening required '../WPNonce/WPNonce.php'
How could i include this php-file (its a class inside)?
I am new in wordpress development. Tried include a selfwritten php-file into htdocs/wp-content/plugins/abc/abc.php
IDE sugesting me to use: require_once '../WPNonce/WPNonce.php';
but WordPress contradicts when opening in webbrowser:
Fatal error: require_once(): Failed opening required '../WPNonce/WPNonce.php'
How could i include this php-file (its a class inside)?
Share Improve this question asked Mar 3, 2019 at 19:02 SL5netSL5net 1054 bronze badges 2- Is the file you want to include part of your plugin? – Qaisar Feroz Commented Mar 3, 2019 at 20:36
- Later i want to be able to use it in all plugins. right now it is in the plugin folder. imgur/tif3vOv – SL5net Commented Mar 3, 2019 at 22:30
1 Answer
Reset to default 1WordPress includes many functions for determining paths and URLs to files or directories within plugins, themes, and WordPress itself.
$plugin_dir = plugin_dir_path( __DIR__ ); // wp-content/plugins/
require_once($plugin_dir.'WPNonce/WPNonce.php');
While using plugin_dir_path()
, keep in mind that the “plugin” part of the name is misleading – it can be used for any file, and will not return the directory of a plugin unless you call it within a file in the plugin’s base directory.
or alternatively, you can also use WordPress constant WP_PLUGIN_DIR
require_once(WP_PLUGIN_DIR.'/WPNonce/WPNonce.php');
I hope this helps.