Last updated August 25, 2009. Created by m3avrck on June 14, 2006.
Edited by lisarex, jhodgdon, bekasu, sepeck. Log in to edit this page.

A simple way to alter your theme based on HTTP headers can be accomplished using the following code:

<?php
  $headers
= drupal_set_header();
  if (
strstr($headers, 'HTTP/1.0 404 Not Found')) {
   
// do something, output something, change template file, etc...
 
}
?>

Works great and works with all other headers. Great for having a completely different layout/theme for 404 pages.

Changing Theme with Init Hook

If you need to actually change a theme, you need to write the following in a module's init hook:

function yourmodule_init() {
   global $custom_theme, $theme;
   //... some logic ...
   $theme = null;
   $custom_theme = 'chameleon'; // 'chameleon' being the theme you want to set
}

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.