3

I've Googled for an answer, but most posts seem to be talking about labels within forms. I have custom fields set up in content block in Drupal 7. When I show the titles (labels) of those custom fields, it adds a colon after after the title. Is there a way to remove them?

3 Answers 3

13

You need to override field.tpl.php to do this (the colon is hard coded into that template file).

Create field.tpl.php anywhere in your theme folder, copy the code from the above link into it, tweak it (remove the colon etc), then clear your caches: all will be well!

1
  • That was it! I couldn't figure out which .tpl file it was for the life of me. Thanks!
    – Brett F
    Sep 21, 2011 at 15:21
5

Override field.tpl.php and add a span (with a class) around the colon, then use CSS to hide the colon. This gives you flexibility in deciding when to hide the colon. For labels set to above you may wish to hide the colon and for labels set to inline you might want to keep the colon.

Example: In your Drupal installation folder, look in modules/field/theme and copy field.tpl.php file to your theme. For D7, edit field.tpl.php and change <?php print $label ?>:&nbsp; to <?php print $label ?><span class="field-label-colon">:&nbsp;</span> In your theme CSS style sheet add .field-label-colon{display: none;} or to only hide label for label above .field-label-above .field-label-colon{display: none;}

1

I just want to add my grain of salt to this topic. I have been trying to do this a few time and I usually end up creating a custom template file for each field I want to remove the column, which is not a good solution in my opinion, because the presence of the label is design dependant; in a good MVC structure, this feature should be controlled by the View (CSS), not the Model (PHP template).

There is what I did this time:

  1. Copy the file modules/field/theme/field.tpl.php into your theme.
  2. Add a span around the column:

    <?php print $label ?><span class="label-suffix">:&nbsp;</span>

  3. Add CSS directives to remove the column where your design required to remove it:

    #sidebar-first .label-suffix { display: none; }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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