Override Drupal theme_function from another module

I wanted to change the related content output html rendered by CCK for my site today. I did a bit of googling, and all of the suggestions pointed to making new field or node specific tpl.php files. While that would work for this site, it's a terrible answer once you start considering using multiple templates. Having dealt with maintenance of what should be exactly the same file / function in different themes being out of sync, I went looking for a more permanent answer. While this might not be the Drupal specific answer, it's very efficient for what I need. So, here's the quick on dirty on how to override the theme function. Note that I suggest doing this only in your own custom module, devoted only to that particular site.

Anything theme_function creates a theme registration. So, go into the registry, and start altering!

  1. function hook_theme_registry_alter($themes) {
  2.   $themes['nodereference_formatter_default']['function'] = 'fragmentedthought_nodereference_formatter_default';
  3. }

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
By submitting this form, you accept the Mollom privacy policy.