What is overriding a theme function and how do I do it?

Category: 
Developer
Topic: 
Code

We often make reference in the forums and documentation to something called "overriding a theme function." What we're referring to is a cool feature of the Drupal theme system. Overriding allows you to change the way the code actually generates HTML for various parts of your website and Ubercart displays. Any function in the API that starts with theme_ may be overridden. (We are documenting these as we can here, but please note that this is an incomplete list.)

If you learn to do this properly, you will be able to customize any display in Ubercart (like the cart block or product pages for example) that you don't like or that don't fit with your site design. A good starting place will be to just copy the entire old function to your theme, rename it accordingly, and add to it or adjust it as the case may require.

Use this Drupal handbook page for information on which file you should place your override functions in and for function naming conventions: http://drupal.org/node/55126

For a concise, clear introduction to overriding theme functions, check out zmove's post on the topic.