at the top of my functions.php I included another PHP file like the example below:
<?php
//file.php
$var1 = "abc";
$var2 = "123"
?>
In functions.php:
<?php
include 'file.php';
// echoing or using the variable in functions.php returns a blank value
?>
In functions.php I included file.php but when I tried to echo $var1 it’s completely blank. Why does it not print "abc"?
2
Answers
You should check the right path to the file you want to include.
for example:
You forgot to add semicolon at the end of the $var2. Please replace with below code.
Also, please make sure that both the files in the same folder. If both he files in different folders, then please use below code to include the file: