Move template function to custom module I have a function in my template.php file but I've now created a module that manages these particular tasks so I want to move the function over.

This is what I have in my template.php file:

function MYTHEME_menu_tree__main_menu($variables){
    return '&lt;ul class="menu my-class"&gt;' . $variables['tree'] . '&lt;/ul&gt;';
}


This works file but when I move it into my custom module (mymodule.module file) if doesn't work.

I've tried this:

function MYMODULE_menu_tree__main_menu($variables){
    return '&lt;ul class="menu my-class"&gt;' . $variables['tree'] . '&lt;/ul&gt;';  
}


and this:

function MYMODULE_preprocess_menu_tree__main_menu($variables){
    return '&lt;ul class="menu my-class"&gt;' . $variables['tree'] . '&lt;/ul&gt;';  
}


but not happening.

Can anyone see where i'm going wrong? or am I way off on this and it can't be done like this?
hook_theme_registry_alter() allows a module to step in to override registered theme callback functions. In your case, you're looking to override the menu_tree__main_menu entry and replace its callback function: 

/**
 * Implements hook_theme_registry_alter().
 */
function MYMODULE_theme_registry_alter(&amp;$theme_registry) {
  if ($theme_registry['menu_tree__main_menu']) {
    // @TODO: override
    // $theme_registry['menu_tree__main_menu']['function']
    // $theme_registry['menu_tree__main_menu']['type']
    // $theme_registry['menu_tree__main_menu']['theme path']
    // for your new module theme function
  }
}


See the Return Value section of hook_theme() for more information on what a theme registry entry contains.