Flipkart

Wednesday, June 8, 2011

Remove colon from label Drupal

To remove Colon from label for form elements just add this below code in to your template.php of the active theme. And replace Theme with your theme name. You can find Original code at includes/form.inc

 
function theme_form_element($element, $value) {
  // This is also used in the installer, pre-database setup.
  $t = get_t();

  $output = '


  if (!empty($element['#id'])) {
    $output .= ' id="'. $element['#id'] .'-wrapper"';
  }
  $output .= ">\n";
  $required = !empty($element['#required']) ? '*' : '';

  if (!empty($element['#title'])) {
    $title = $element['#title'];
    if (!empty($element['#id'])) {
      $output .= ' \n";
    }
    else {
      $output .= ' \n";
    }
  }

  $output .= " $value\n";

  if (!empty($element['#description'])) {
    $output .= '
'. $element['#description'] ."
\n";
  }

  $output .= "
\n";

  return $output;
}

4 comments:

  1. Thanks for your post, but this do not work for me..i'm trying to hide colon of all field label, in drupal 7, for a specific content-type..
    your code have some syntax error (i tried to fix it, but seems wrong). Can you fix it?
    Thanks in advance

    ReplyDelete
  2. HI Macro,

    I used this code in Drupal 6. I don't know whether it will work in Drupal 7.

    I will try to change this code as per Drupal 7 format.

    ReplyDelete
  3. Hi Macro,

    In Drupal 7, Content type fields does not contains Colon

    ReplyDelete
  4. drupal has a no colons module and in D8 there is a checkbox for this in core for each field

    ReplyDelete