The proper way to include/require PHP files in WordPress
I'm a new WordPress developer and recently I've been having problems (on multiple sites) with include_once
and require_once
for PHP files. If I include (get_theme_directory_uri() . 'subdir/file')
the specified file gets included (or required, which leads to fatal errors) but if any WordPress functions are called within 'file' I get something similar to:
'Call to undefined function
add_action()
in /full/path/to/file'.
The apparent solution I've found is to do:
include(dirname(__FILE__) . "/subdir/filename");
Is this right or did I miss 'the WordPress way' to include files somewhere?
Topic include theme-development themes Wordpress
Category Web