Last Updated: February 25, 2016
·
553
· webinity

Assign a specific theme to a module page or menu item

In Drupal 7 there is a new menu item parameter called "theme callback". This parameter acts similar to the "page callback" but it basically refers to a function to get apply a theme to the page.

So if for example there are 2 enabled themes ( Important that the theme is enabled otherwise it could not work ) and you would like to change the default theme for a specific page, you can set the theme callback and return the theme name string in the function you specify.

function mymodule_menu()
{
    $items = array();

    $items['user/account'] = array(
            'title' => t('Personal Account'),
            'page callback' => 'account_page',
            'access arguments' => array('access content'),
            'file' => 'user.account.inc',
            'theme callback' => 'mymodule_default_node_theme',
    );
    return $items;
}

function mymodule_default_node_theme() {
    return 'mythemename'; //return the name of the theme
}