1

Field labels can be hidden for a content type by going to "Manage display" and changing the labels to hidden.

However, I rarely need to show labels.

Is there a way to have the labels hidden by default, site-wide?

2 Answers 2

0

I think preprocess_node should do the trick

use that in your template.php

function template_preprocess_node(&$vars){
  //Supposing that your content type name is "group"
  if($vars['type'] == 'your type'){
    $vars['content']['your_field']['#title'] = '';
  }
}
2
  • Please could you give a bit more detail?
    – Hugo
    Jan 22, 2016 at 14:28
  • I've added the code above, preprocess_node seems to be the one.
    – GwenM
    Jan 22, 2016 at 14:43
0

Use hook_field_create_instance() to hide content type labels by default.

<?php
// implementation of hook_field_create_instance()
// sets all labels to Hidden for new fields
function MODULENAME_field_create_instance($instance){
  // fetch the instance info
  $instance_info = field_info_instance(
    $instance['entity_type'],
    $instance['field_name'],
    $instance['bundle']
  );

  // set label in each display to hidden
  foreach( $instance_info['display'] as &$display ){
    $display['label'] = 'hidden';
  }

  // save back to disk
  field_update_instance($instance_info);
}
?>
1
  • When I added a new field to a content type with this code in place, the label was "Above".
    – Hugo
    Jan 25, 2016 at 10:51

Your Answer

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

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