8.5.x theme.api.php hook_theme_registry_alter(&$theme_registry)
8.0.x theme.api.php hook_theme_registry_alter(&$theme_registry)
8.1.x theme.api.php hook_theme_registry_alter(&$theme_registry)
8.2.x theme.api.php hook_theme_registry_alter(&$theme_registry)
8.3.x theme.api.php hook_theme_registry_alter(&$theme_registry)
8.4.x theme.api.php hook_theme_registry_alter(&$theme_registry)
8.6.x theme.api.php hook_theme_registry_alter(&$theme_registry)
6.x core.php hook_theme_registry_alter(&$theme_registry)
7.x system.api.php hook_theme_registry_alter(&$theme_registry)

Alter the theme registry information returned from hook_theme().

The theme registry stores information about all available theme hooks, including which callback functions those hooks will call when triggered, what template files are exposed by these hooks, and so on.

Note that this hook is only executed as the theme cache is re-built. Changes here will not be visible until the next cache clear.

The $theme_registry array is keyed by theme hook name, and contains the information returned from hook_theme(), as well as additional properties added by _theme_process_registry().

For example:

$theme_registry['user_profile'] = array(
  'variables' => array(
    'account' => NULL,
  'template' => 'modules/user/user-profile',
  'file' => 'modules/user/user.pages.inc',
  'type' => 'module',
  'theme path' => 'modules/user',
  'preprocess functions' => array(
    0 => 'template_preprocess',
    1 => 'template_preprocess_user_profile',


$theme_registry: The entire cache of theme registry information, post-processing.

See also



Related topics

1 invocation of hook_theme_registry_alter()
_theme_build_registry in includes/theme.inc
Builds the theme registry cache.


modules/system/system.api.php, line 2366
Hooks provided by Drupal core and the System module.


function hook_theme_registry_alter(&$theme_registry) {

  // Kill the next/previous forum topic navigation links.
  foreach ($theme_registry['forum_topic_navigation']['preprocess functions'] as $key => $value) {
    if ($value == 'template_preprocess_forum_topic_navigation') {
      unset($theme_registry['forum_topic_navigation']['preprocess functions'][$key]);


peterx’s picture

This function is fired once to build everything for all themes on all pages. If you want to modify a theme for some pages, I suggest you set up a subtheme for those pages and use something like the themekey module to show the subtheme on the special pages. You can then alter the subtheme.

Alan D.’s picture

In hook_theme(), specifying the 'file' parameter will automatically prefix the right base path or your own specified base path to this file using 'path'. This is done before hook_theme_registry_alter(), so rather than supplying these, append the full path to the 'includes' parameter.


function base_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'base');
  // Override the content type summary info.
  if (isset($theme_registry['node_admin_overview'])) {
    // This is how it is done in hook_theme(), but it does not work here.
    // $theme_registry['node_admin_overview']['file'] = 'node_admin_overview.inc';
    // $theme_registry['node_admin_overview']['path'] = $path . '/theme';

    $theme_registry['node_admin_overview']['includes'][] = $path . '/theme/node_admin_overview.inc';
    $theme_registry['node_admin_overview']['function'] = 'base_node_admin_overview';
Sebastien @Actualys’s picture

Here is my snippet to declare views templates stored in the "template" folder of my "custom_module":

 * Implements hook_theme_registry_alter().
function custom_module_theme_registry_alter(&$theme_registry) {
  $extension   = '.tpl.php';
  $module_path = drupal_get_path('module', 'custom_module');
  $files       = file_scan_directory($module_path . '/templates', '/' . preg_quote($extension) . '$/');

  foreach ($files as $file) {
	$template = drupal_basename($file->filename, $extension);
	$theme    = str_replace('-', '_', $template);
	list($base_theme, $specific) = explode('__', $theme, 2);

	// Don't override base theme.
	if (!empty($specific) && isset($theme_registry[$base_theme])) {
	  $theme_info = array(
		'template'   => $template,
		'path'       => drupal_dirname($file->uri),
		'variables'  => $theme_registry[$base_theme]['variables'],
		'base hook'  => $base_theme,
		// Other available value: theme_engine.
		'type'       => 'module',
		'theme path' => $module_path,

	  $theme_registry[$theme] = $theme_info;

Hope it helps someone.

araujo.guntin’s picture

Hi Sebastien,

I'm using D7 and I got an error: the 'variables' is not defined.

Using D7, how could I use your code?

I appreciate your help.