Including External View Files in WordPress Widgets

I ran into a problem today while cleaning up and modifying some widgets. I moved all of the markup inside widget() to an external view file, and then included it via require_once(), which worked fine. I then tried to do the same thing inside form(), but didn’t get any output. It turns out that you can’t use include_once() or require_once() inside form(), you have to use include() or require() instead. It’s a good idea to use include() or require() anyway, though, in case the widget has multiple instances.

Leave a Reply

Your email address will not be published. Required fields are marked *