Drupal - How do I remove the colon from my field labels?

The answer is definitely to use field.tpl.php. If you look at the source for that file you can see the offending lines:

<?php if (!$label_hidden): ?>
  <div class="field-label"<?php print $title_attributes; ?>>
    <?php print $label ?>:&nbsp;
  </div>
<?php endif; ?>

(spacing and indentation mine for clarity).

Removing the colon is as simple as replacing the above lines with:

<?php if (!$label_hidden): ?>
  <div class="field-label"<?php print $title_attributes; ?>>
    <?php print $label ?>&nbsp;
  </div>
<?php endif; ?>

I've just tested that on a blank Drupal installation and it works perfectly; no more colons after field labels.

If you're already doing the same thing, but not getting the correct results, then I can think of one or two things that could be going awry:

  • You've put your custom version of field.tpl.php into a module folder, rather than in your site's active theme folder (it needs to be in the theme folder).
  • Another module/element in the system is also overriding field.tpl.php, in a more robust manner than you currently are. Seeing if this is the case will involve the always-tedious disabling of each enabled module to determine where the problem is coming from.

You won't be able to make the change with a template preprocess function, as the colon is hard-coded into the template file.


I just created a module which does exactly this, removes colons (on a per field basis) from field labels on output: Colectomy


If it is a View with fields, just click on the field and uncheck "Place a colon after the label" under "Create label".

Tags:

Entities

7