‘global’ not working in wordpress?

Don’t use globals, but if you must use them you should explicitly declare them as such. WordPress includes theme files from functions therefor a $test = 1; will be evaluated in the context of the function and the variable $test will be implicitly declared in the context of the function but not as a global.