• I am using one of the pages, to display a list. I have the following in the page:

    <? php
    include_once "myFunctions.php";
    include_once "myDeclarations.php";
    displayText();
    ?>
    
    Inside myFunctions.php, I have the following function:
    
    function displayText() {
    GLOBAL $textToDisplay;
    echo "Testing WordPress";
    echo $textToDisplay;
    }

    Inside myDeclarations.php, I have the following:

    $textToDisplay = “This is a test”;

    When I go to that page, it only displays: Testing WordPress. The variable $textToDisplay is not passed. It seems as if the include file that has the function in it, is recognized, but the variable in the other file, is not. How do I deal with this scope issue in WordPress?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Variables scope’ is closed to new replies.