can require “themefolder/includes/widgets.php” in “themefolder/functions.php” yet widgets.php doesn’t run

The first location where PHP would look for relative path will not be the file you specify include in, but relative to point of entry file (index.php or whatever).

Files are included based on the file path given or, if none is given, the include_path specified. If the file isn’t found in the include_path, include will finally check in the calling script’s own directory and the current working directory before failing.

http://php.net/manual/en/function.include.php

My guess would be that your code picks up wp-admin/includes/widgets.php (because in admin context the point of entry is likely wp-admin/index.php) instead of your file.

Always write includes like require( __DIR__ . '/includes/widgets.php' );

Leave a Comment