Use a different theme when your site is being embedded in an iframe We have the requirement to make a trimmed back version of the website, for use for other websites to embed via an iframe. For instance, there will be no left navigation, no global navigation, and all elements will be re-flowed to fit in a smaller width.

I would like to do this with a separate theme (more than likely the iframed theme would be a sub theme of the main site theme).

What is the best way to ensure the site loads the alternative theme when it has been embedded (and switch back to the main theme when it is not)?

A thought I had:


Use a different sub-domain e.g. www.example.com and iframe.example.com


I am after what you think the best way to solve this would be
Create a custom module and put this lines there:

/** Implementation of hook_init **/
function yourmodule_init(&amp;$vars) {

  //here put any condition to you want, for example a domain
  $url = url("&lt;front&gt;", array('absolute' =&gt; TRUE));
  if( $url == "http://mydomainiframe.com") {
    global $custom_theme;
    $custom_theme = 'new-theme'; //setting a new theme for this domain.
    init_theme();
  }
}


Also you can avoid create a whole new theme creating only a new page.tpl.php and using it.

/** preprocess_page **/
function your_module_preprocess_page(&amp;$vars) {

  //here put any condition to you want, for example a domain
  $url = url("&lt;front&gt;", array('absolute' =&gt; TRUE));
  if( $url == "http://mydomainiframe.com") {
    $vars['template_file'] = 'page-iframe'; //setting a new page template
  }
}


And the page-iframe.tpl.php will be used instead of the page.tpl.php of your theme, in this way you can reuse things to you have in your actual theme.