Fragmented Thought

Override Drupal theme_function from another module

By

Published:

Lance Gliser

Heads up! This content is more than six months old. Take some time to verify everything still works as expected.

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 p ointed 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!

function hook_theme_registry_alter($themes) { $themes['nodereference_formatter_default']['function'] = 'fragmentedthought_nodereference_formatter_default'; }