I have a WordPress-theme that has to be used on multiple sites. So I wrote this function, to determine which site the theme is on:
/*
* Check which site
*/
function determine_site() {
$the_site = '';
$URL = $_SERVER['HTTP_HOST'];
switch( $URL ){
case 'domain1.com':
case 'develop1.ment.com':
$the_site = 'domain1_com';
break;
case 'domain2.com':
case 'develop2.ment.com':
$the_site = 'domain2_com';
break;
default;
$the_site = 'domain_undetermined';
break;
}
return $the_site;
}
And this function is then called from another function, which adds it to the body-class on the site, as such:
/*
* Add body class
*/
function add_custom_body_class( $classes ) {
$which_language = determine_site();
$classes[] = $which_language;
return $classes;
}
add_filter( 'body_class', 'add_custom_body_class' );
But it reaches the default-case and sets domain_undetermined
as the body
-class (which it should match on one of the first cases). If I print out the $URL
-var in the top of the determine_site
-function, as such:
function determine_site() {
$the_site = '';
$URL = $_SERVER['HTTP_HOST'];
echo '<pre>;
print_r($URL);
echo '</pre>;
...
...
...
Then it outputs this (!?):
develop1.ment.comclass="home page-template-default page page-id-11 logged-in admin-bar no-customize-support wp-custom-logo domain_undetermined">
Why does it print the end of the body
-classes, as well?
Another thing that might help figure out where the hatchet is burried... If I run sanitize_title
(a WordPress-function) on $URL
, as such:
function determine_site() {
$the_site = '';
$URL = $_SERVER['HTTP_HOST'];
$URL = sanitize_title( $URL );
echo '<pre>';
print_r($URL);
echo '</pre>';
...
...
...
... Then it returns this (even though I am on the develop1.ment.com
-domain:
www-domain1-comclass="home page-template-default page page-id-11 logged-in admin-bar no-customize-support wp-custom-logo domain_undetermined">
The development-server does some proxy-stuff, which explains this last bit, - but it doesn't explain all of these mysteries.