Right way to call theme functions in Drupal

Right way to call theme functions in Drupal

Drupal core and contrib modules defines theme functions. These theme functions can be defined by themes as well.

hook_theme() implementations is where all the information exists. Theme functions are writen as hook_foo() or hook_fooxyz(), but we should never call a theme function directly. By calling it directly we will loose the benefits of Drupal theming layer such as overriding, suggestions, etc.

Example on how to call theme_image() the right way:

Right way

print theme('image', array('path' => 'image/path/image.png', 'alt' => 'New image'));

Wrong way

print theme_image(array('path' => 'image/path/image.png', 'alt' => 'New image'));

 

Further information and documentation can be found at https://api.drupal.org/api/drupal/includes%21theme.inc/function/theme/7.