my functions.php file is just a placeholder for many different functions. I have another file settings.php that I use to store different settings. Some of the functions in functions.php will need to access some of the variables in settings.php, so I tried:
require("settings.php")
on top of the functions.php file, but that does not seem to give my functions access to the variable in settings.php. I need to put require(“settings.php”) in every function separately.
Is there a way I can declare the variables in settings.php to be accessible globally to all functions defined in functions.php?
Thank you,
You need to modify your functions in
functions.phpto use global variables defined insettings.php.Inside
settings.php;By using the
globalkeyword:Or more preferably, using the
$GLOBALS[]superglobal array. Any variables declared at global scope, like I assume your settings.php vars are, will be included as array keys in$GLOBALS[]. It’s a little better for readability than using theglobalkeyword inside each function.