I’m currently developing a website where I need a widget to display the upcoming match. The site is for a football team. I’ve therefore created a plugin which creates a custom post type and a widget. Everything is working really well, but as I don’t like to clutter my PHP code with HTML I figured I’d include the widget settings in from another file in the plugin directory. Although the include returns bool(true) nothing is showing in the widget form.
Here is the code I’m using to include the file:
public function form($instance){
require_once($this->plugin_directory.'/views/widget-form.php');
}
The variable $this->plugin directory is defined in the constructor and points to the correct path.
Here is the html code inside the included file, it’s brief but just to test. No matter what I type in there it keeps returning blank.
<input type="text" name="title" value="Hello World!" />
Any ideas why this keeps happening, or doesn’t WordPress support loading extra files in places like this? I could just have my html in the plugin-file, but I prefer to keep PHP clean, and not cluttered with HTML and/or CSS, JS etc.
If anyone could help me figure this out I would greatly appreciate it! 🙂
Thanks in advance,
Jonathan
I know you’ve mentioned that your $this->plugin_directory is set in the constructor as the correct path, have you tested the output of this and/or is it set as the absolute path or relative?
I’ve had issues in the past where plugin files couldn’t read the relative path correctly and so therefore I had to switch to an absolute path instead or vice-versa.