WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is the php $GLOBALS associative array over written in WordPress with the WordPress $GLOBALS? I have a piece of code that uses $GLOBALS['myvariablename'] to access a global variable. It works in php, but stops working when I bring the code to a WordPress environment.

Is there a way to use $GLOBALS associative array? Or should I absolutely declare variables global before getting them in functions and using them?

Added Later:

My code: http://bharath.lohray.com/sources/redditGetVotes.phps

I am trying to use the reddit API to fetch and display the popularity of my links on my wordpress blog. The global variables are for configuration information - like the reddit user name etc. I have documented my steps in my post here.

share|improve this question
You shouldn't use $Globals at all, but where and how are you placing this global? – Wyck Oct 6 '13 at 16:58
Post your code, please. globals are best avoided if possible, but for what it is worth I have not noticed any real issue with them if you understand how they work. – s_ha_dum Oct 6 '13 at 17:07
@s_ha_dum: Updated question. My Code is at bharath.lohray.com/sources/redditGetVotes.phps It is workign for now, but I cannot use $GLOBALS['variableName'] as an associative array. – Lord Loh. Oct 6 '13 at 22:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.