• I am including a script into my wordpress, which is not working. I’ve narrowed it down to the script’s global variables not working. Here is an example that I put into my sidebar and it does not work. I would like to figure out why its not pulling the variable so I can edit the script to work with it.

    $myvar = "testing";
    function test_func()
    {
    global $myvar;
    echo $myvar;
    }
    test_func();

    Thanks for your help!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Check your php calls.

    That may sound stupid but try to make it global first.

    global $myvar;
    $myvar = “testing”;

    function test_func()
    {
    global $myvar;
    echo $myvar;
    }

    test_func();

    Thread Starter jabbaonthedais

    (@jabbaonthedais)

    ‘Check your php calls.’

    I’m not sure what you mean.

    ‘That may sound stupid but try to make it global first.’

    That works! Thanks… but is that the correct syntax? I double checked php.net and didn’t see that you had to declare them as global before the function.

    I’m wanting to know if thats how it should be written as I will just edit the script.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘global variables not working’ is closed to new replies.