What's the best way to alter the field label for a given node type, and maybe even for a specific view mode?

For now, I've used a field template in the form field--[name]--[node-type].tpl.php but I'm wondering if it would be better to use a hook field alter function?


You could implement hook_field_attach_view_alter() in a custom module or in template.php of your theme. The first argument, $output, is a render array for all fields in the node being viewed. You can modify the title of the body field, for example, by altering the #title property, as in

$output['field_my_field']['#title'] = 'My awesome title';

The $context parameter includes the entity_type, entity and view mode among other things, which you could use in if statements. You can get the bundle from the entity itself, as in $context['entity']->bundle();

Excellent, thank you!

Adding the link here for reference.