• veneficusunus

    (@veneficusunus)


    Apologies for the long title.

    Basically I just want to know why when I define a variable in functions.php it can’t be accessed in header.php etc unless I globalize the variable inside header.php first.

    Functions I define can be ran no problem, but variables have the value NULL (unless globalized).

    I’m newish to theme dev so was wondering if it’s always been like that, if so why, and can anyone suggest an alternative to making a variable accessable to the entire theme.

    Thanks for any help.

Viewing 3 replies - 1 through 3 (of 3 total)
  • esmi

    (@esmi)

    WordPress doesn’t use standard PHP includes – so variables defined outside of a function, that is itself called within a template file, won’t work.

    Thread Starter veneficusunus

    (@veneficusunus)

    Ahh ok, thanks for that.

    So if I define the variable in header.php instead will it be available to all the template files? Or is there an easier way to make my variable accessable to every theme file. I would use a constant but the value isn’t scalar.

    Thanks for your help so far, and for any more you can give.

    MichaelH

    (@michaelh)

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Variables defined in functions.php not accessable elsewhere’ is closed to new replies.