8.2.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)
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(
  'arguments' => array(
    'account' => NULL,
  'template' => 'modules/user/user-profile',
  'file' => 'modules/user/user.pages.inc',
  'type' => 'module',
  'theme path' => 'modules/user',
  'theme paths' => array(
    0 => '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
Rebuild the hook theme_registry cache.


developer/hooks/core.php, line 2258
These are the hooks that are invoked by the Drupal core.


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]);


zeropaper’s picture

Unlike the hook_theme this hook can not be used within a theme.

Alphabool’s picture

I struggled with a fundamental misconception when trying to re-theme the theme_username() function using hook_theme_registry_alter. After redefining $theme_registry['username']['function'] as a function definition in my custom module, I expected theme_username() to use my new function definition. It never will.

As I found out, theme_username() calls the core function directly, whereas theme('username',arg1,arg2) queries the theme registry first. So whereas calling theme_username() will never call the function defined in hook_theme_registry_alter, calling theme('username',...) will call that new function.

I hope I save someone the hour I wasted figuring this out :P

Garrett Albright’s picture

Almost never do you want to theme stuff by calling theming functions directly instead of using the theme('foo', …) format. And this is one example why. It's considered incorrect Drupal coding style to do so.

sunildias’s picture

Hope you might have missed to rebuild the theme registry. Rebuilding the theme registry will helps to override.

I just came across this forum and understood the response very very late we are moving to D8. :)...

nicl’s picture

See: http://www.lullabot.com/articles/overriding-theme-functions-in-modules for one example of why this hook can be useful.