The truth is rarely pure and never simple

Drupal: select theme by domain / HTTP_HOST

Sometimes, it may be helpful to select a Drupal 6 theme depending on the domain being used for every request. Although there are full-fledged solutions like Domain Access, they may be considered overkill for this problem.

A reliable and quick solution is a custom module which is also compatible to a multisite drupal installation. Let’s call our sample module fooselect. Then create the directory fooselect either in /drupal/modules/ or /drupal/site/DOMAIN/modules/. Add the two following files to this directory:

fooselect.info

name = fooselect
description = domain switch
core = 6.x

fooselect.module

<?php
$custom_theme = variable_get('theme_default', '0');

function fooselect_init() {
  if ($_SERVER['HTTP_HOST'] == 'subdomain.example.com') {
    global $custom_theme;
    $custom_theme = 'othertheme';
    init_theme();
  }
}

After activation of this module, you have to adjust the second file to suit your needs, in particular the selection logic, the theme name and the domain names.

Leave a comment

Your email address will not be published.