Drupal 7: Multi theme (or) Theme per each page

In Drupal theme provide the design for the pages and contents. We can use multiple themes for our website. Using the user role, permission and page URLs we can able to change the theme. This is the simple example of implementing theme per page by URL.

The Hook hook_custom_theme() helps us to change the theme of the current page.

Syntax: 

/**
 * Implements hook_custom_theme().
 */
function MODULENAME_custom_theme() {
  if (CONDITION_1) {
    return THEME_1;
  }
  elseif(CONDITION_2) {
    return THEME_2;
  }
  elseif(CONDITION_3) {
    return THEME_3;
  }
  else {
    return DEFAULT_THEME;
  }  
}

Example: 

/**
 * Implements hook_custom_theme().
 */
function codeexpertz_custom_theme() {
  if (arg(0) == 'admin') {
    return "seven";
  }
  elseif (arg(0) == 'blog') {
    return "honeypot";
  }
  elseif (arg(0) == 'extras') {
    return "bootstarp";
  }
  else {
    return "bartik";
  }
}

 

Category: