Is there a way to force a page to be rendered in admin theme, Like pages that their path begins with 'admin/'?


There is a contrib module ThemeKey that

allows you to define simple or sophisticated theme-switching rules which allow automatic selection of a theme depending on current path, taxonomy terms, language, node-type, and many, many other properties. It can also be easily extended to support additional properties exposed by other modules. In combination with Drupal's theme inheritance and ThemeKey Properties you can easily achieve features like:

individually-styled channels a front-page / "splash" screen a date/time-selected Christmas theme mobile themes for different auto-detected mobile devices special themes for "limited" or "old" browsers content, user, or role -specific themes indicating your environment (production, staging, testing, sandbox, … ) testing your redesign safely on a live server

Check also related question here.


You can also do this by making a custom module.

Method 1

Use this if you want to theme an existing page, based on Drupal's internal path (aka path source). This example uses hook_custom_theme.

function MYMODULE_custom_theme() {
  // match node/1
  if (arg(0) == 'node' && arg(1) == '1') {
    return variable_get('admin_theme');

Method 2

Use this if you want to theme an existing page, based on URL path (aka path alias). This example also uses hook_custom_theme.

function MYMODULE_custom_theme() {
  // get arguments
  $arg = explode('/', substr(request_uri(), strlen(base_path())));
  // match {wildcard}/path 
  // Using strpos as $arg[1] may end up having stuff like so ?order=title&sort=asc
  if (isset($arg[1]) && strpos($arg[1], 'path') !== false && !isset($arg[2])) {
    return variable_get('admin_theme');

Method 3

Use this if you want to theme and create a page. This example uses hook_menu. To learn more, take a look at another great article on hook_menu.

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

  // match some/path
  $output['some/path'] = array(
    'title' => t('Page Title'),
    'page callback' => 'MYMODULE_page',
    'theme callback' => 'variable_get',
    'theme arguments' => array('admin_theme'),

function MYMODULE_page() {
  return 'Hello world.';

If you are a module developer, you can use hook_admin_paths to define which paths are to be rendered with the administration theme.


Simply give the page a path beginning with admin: 'admin/mypage'

  • 1
    Why the downvote? This functionality is in D7 core, the question does not specify which version, but at time of posters question D7 was released. Jul 30 '14 at 19:56
  • Yep, perfectly sensefull comment IMO.
    – Countzero
    Oct 27 '14 at 9:00
  • 2
    it doesn't seem that custom pages beginning with 'admin/' necessarily load the admin theme.
    – DrCord
    Mar 3 '15 at 21:50
  • perfect and simplistic for views! Sep 28 '16 at 16:07
  • This does not work.
    – Christia
    May 2 '17 at 8:07
  1. This functionality is now in D7 core.

  2. There's a module that effectively exposes "hook_admin_paths" to the UI: https://drupal.org/project/admin_theme

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.