Multisite does not appreciate relative paths in require_once() calls

Who knew? Oh you did? *cough* Yeah me too. D’uh.

It’s obvious if you think about. But of course problems typically arise from things you haven’t thought about. Are you loading something in your plugin or theme using a relative path?

require_once( 'loadme.php' );

If you’re running a multisite network that won’t cut it. Instead use the plugin_dir_path:

require_once( untrailingslashit( plugin_dir_path( __FILE__ ) ) . DIRECTORY_SEPARATOR . 'loadme.php' );

Or the (parent) theme directory with get_template_directory():

require_once( get_template_directory() . DIRECTORY_SEPARATOR . 'loadme.php' );

Even if you’re not running a multisite network, use the full path out of courtesy for the rest of us. And if you’re developing a plugin or theme, install multisite locally so you’re testing in that environment.


For the rest of us.