Changing theme based on http headers

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.

Actual Change of a Theme

irakli - April 18, 2008 - 03:42

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
  
}

 
 

Drupal is a registered trademark of Dries Buytaert.