I use subdomains with the same template and I try to use filter template_directory to replace serverName by $_SERVER['HTTP_HOST']
but it doesn't work .
The default page is www.website.com and the user must choose one of three spaces "move.website.com", "visit.website.com", "live.website.com". For each three spaces I created a subdomain ! I want to use the same template for each subdomain.
For that I redirect each subdomain to the template. Using $_SERVER['HTTP_HOST'] with the if condition inside index.php I can choose which file or code to display in fonction of subdomain . But now I must modify all links (bloginfo(template_directory)) to add subdomain at the beginning to url.
The relative url used by get_template_directory
is still the same as default using filter - the subdomain isn't added :
add_filter( 'template_directory', function( $template_dir ){
$subdomain = 'https://' . $_SERVER['HTTP_HOST'];
return str_replace( 'https://website.com', $subdomain , $template_dir_uri );
});
I should get https://subdomain.website.com
template_directory_uri
.add_filter( 'template_directory', function( $template_dir ){ $subdomain = 'https://' . $_SERVER['HTTP_HOST']; return str_replace( 'https://website.com', $subdomain , $template_dir );});
andadd_filter( 'template_directory_uri', function( $template_dir_uri ){ $subdomain = 'https://' . $_SERVER['HTTP_HOST']; return str_replace( 'https://website.com', $subdomain , $template_dir_uri );});
doesn't do anything .get_template_directory
doesn't return a URL