So, I have a Wordpress theme.
In the functions.php file, I'm writing a function that looks something like this:
function my_function(){
$var1 = 'apple';
$var2 = 'orange';
include get_bloginfo('stylesheet_directory').'/lib/fruits.php';
}
And the fruits.php file looks like this:
<?php
echo "My brother's favorite fruit is an $var1, but my favorite fruit is an $var2.";
?>
When I call my_function() somewhere in my theme, the echo statement in fruits.php displays on the screen, but the values of $var1 and $var2 do not display. They're simply blank.
Now here's the strange part. If I move fruits.php to the same directory as functions.php, and change the include statement in my_function() to this:
include 'fruits.php';
the 2 variables display just fine.
Any ideas what could be causing this problem?
FYI, I did try defining the path to fruits.php in a variable and then trying
include $path;
to no avail.