0

I created an mu-plugins folder with this block of code in it:

if ( $_SERVER["HTTP_HOST"] === "domain1.com" ) { $sitetype = one; }
if ( $_SERVER["HTTP_HOST"] === "domain2.com" ) { $sitetype = two; }
if ( $_SERVER["HTTP_HOST"] === "domain3.com" ) { $sitetype = three; }

Basically, what I want to do is assign a $sitetype (basically a category) to a wordpress site and change things up based on the current domain name.

The code I have in my wordpress header file is:

if ( $sitetype == all ){ echo "site type 1"; }
if ( $sitetype == viral ){ echo "site type 2"; }
if ( $sitetype == woman ){ echo "site type 3"; }

With the 1st code block, it doesnt work when inside the mu-plugins folder but if i move it right above the 2nd code block in the header file it works fine so i think its executing incorrectly while in the mu-plugins folder. Is there a way I can keep the code in the mu-plugins folder and to get this to work the same way?

2
  • 1
    You need to declare it global global $site_type; in both places before using. – bonger Feb 13 '16 at 21:47
  • 1
    @bonger can u put it as an answer so i can mark this as correct in case someone else comes across this? – Joe Bobby Feb 13 '16 at 23:39
2

Per comments, declare it global before using in both (or all) places:

global $sitetype;
if ( $_SERVER["HTTP_HOST"] === "domain1.com" ) { $sitetype = one; } //etc

and

global $sitetype;
if ( $sitetype == all ){ echo "site type 1"; } //etc
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.