Timeline for Pass a PHP variable to another file
Current License: CC BY-SA 4.0
5 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 27, 2019 at 14:09 | comment | added | maryisdead |
@EvanMeredith-Davies This works. Tested it in a vanilla WordPress installation. global needs to be used in the file/place where you want to access the variable, not where you define it. Your second code snippet, which file exactly is this in?
|
|
Nov 27, 2019 at 14:06 | comment | added | maryisdead | @kero It's WordPress. The global namespace already is a radioactive soup. There are of course more "elegant" solutions, but sometimes this is overkill and certainly out of scope here. | |
Nov 27, 2019 at 12:57 | comment | added | Evan Meredith-Davies | Wouldn't 'global' need to be written in the template where the the variable is first defined? ``` global $critical_css = 'cc-frontpage'; ``` neither work unfortunately :( | |
Nov 27, 2019 at 12:34 | comment | added | kero |
I think "polluting" the global space like this is considered bad practice
|
|
Nov 27, 2019 at 10:35 | history | answered | maryisdead | CC BY-SA 4.0 |