Drupal - How do I get a field label by the field name?

The label is set per instance (not per field) so you would use the field_info_instance() function with some appropriate arguments:

$entity_type = 'node';
$bundle_name = 'article';
$field_name = 'field_some_field';

$info = field_info_instance($entity_type, $field_name, $bundle_name);

$label = $info['label'];

There's a bunch of other useful functions in the Field Info API documentation that might be helpful in case you haven't seen it already.


The easiest way to print the field label of a node is:

<?php print $content['field_your_field_name']['#title']; ?>

(I've discovered it after a lot of print_r arrays and objects of Drupal! If it's so easy, why isn't explained anywhere, or why is so hidden that I've not found the trick? And passed a long time from the question to this answer...)

Tags:

Entities

7