I am trying to override the 'link_field' theme function in the Link module. I've put this function in my template.php of my active theme and have cleared the cache, but its not overriding. What am I doing wrong?

 function tma_corp_link_field($vars) {
  drupal_add_css(drupal_get_path('module', 'link') . '/link.css');
  $element = $vars['element'];
  // Prefix single value link fields with the name of the field.
  if (empty($element['#field']['multiple'])) {
    if (isset($element['url']) && !isset($element['title'])) {
      $element['url']['#title_display'] = 'invisible';

  $output = '';
  $output .= '<div class="link-field-subrow clearfix">';
  if (isset($element['title'])) {
    $output .= '<div class="link-field-title link-field-column">' .      drupal_render($element['title']) . '</div>';
  $output .= '<div class="link-field-url' . (isset($element['title']) ? ' link-field-column' : '') . '">' . drupal_render($element['url']) . '</div>';
  $output .= '</div>';
  if (!empty($element['attributes']['target'])) {
    $output .= '<div class="link-attributes">' . drupal_render($element['attributes']['target']) . '</div>';
  if (!empty($element['attributes']['title'])) {
   $output .= '<div class="link-attributes">' . drupal_render($element['attributes']['title']) . '</div>';
  if (!empty($element['attributes']['class'])) {
   $output .= '<div class="link-attributes">' . drupal_render($element['attributes']['class']) . '</div>';
  return $output; 
  • 1
    Just to check, your theme is called tma_corp and is active, right ?
    – rtome
    Commented Mar 9, 2015 at 21:02
  • to add to the above comment, If this is on a node creation page, the active theme on this page will be the admin theme, so your function will need to go in your admin themes template.php
    – 2pha
    Commented Mar 10, 2015 at 5:34
  • If it is on an admin page and you are using an admin theme (or if you prefer to keep your code in modules over themes), consider using hook_theme_registry_alter() in a custom module.
    – Webdrips
    Commented Mar 10, 2015 at 9:16
  • @Webdrips - Thanks! You were correct about it being on the admin theme, I didn't think about that and the hook_theme_registry_alter did the trick. Please create an answer and I will accept it. Commented Mar 10, 2015 at 15:47

1 Answer 1


So to help keep your theme files cleaner, the preference is to place theme overrides in a custom module. This allows you to switch themes without having copy, paste, and rename a bunch of code.

Also this may be your only choice if, for example, you're trying to override a theme function that's being called from an admin page, you have an admin theme enabled, and you don't want to bother with creating a subtheme for your admin theme.

The workaround here is to use hook_theme_registry_alter(); see this page on Drupal Stack Exchange.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.