I’ve created a widget plugin and have placed the code for displaying the front end content in a separate file. I’m linking to the file using include_once but keep getting the error, failed to open stream: No such file or directory in... The plugin folder contains 2 subfolders: includes and tpls The file I’m linking to is in the tpls folder and I’m linking to it from the includes folder. This is the code I’m using to link to the file:

// Creating widget front-end
public function widget( $args, $instance ) {

include_once('../tpls/frontend.php' );

I'm not sure if I'm supposed to have a forward slash before tpls but I tried it both ways and I still get the error.

1 Answer 1


I got this to work by using include_once(plugin_dir_path( __FILE__ ) . '/../tpls/frontend.php'); The file I'm using include_once in is itself included from the index.php file in the plugin's root directory so, according to the documentation on the subject, a relative path to the file will be relative to the root directory, not the inc folder. However, in that case I expected to be able to include the file like this: include_once('./tpls/frontend.php'); but after testing it I found it doesn't work as expected.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.