Remove title from hook_entity_view I need to remove title from rendered custom entity.

unset($entity-&gt;title) is not good because i still need to use its value in this rendered entity to use in markup.

css display:none is not good idea on my point of view as well.
hook_entity_view(), and hook_entity_view_alter() are not the hooks you should use to avoid an entity title is rendered, as the entity title is not generally passed to the $build parameter passed to those hooks.

This is the content of the $build parameter for three different entity Drupal defines.


Node


Comment


Taxonomy term




Furthermore, the purpose of hook_entity_view() is adding content to $entity-&gt;content, not altering $entity. The description given in the documentation page for the hook is the following:


  The module may add elements to $entity-&gt;content prior to rendering. The structure of $entity-&gt;content is a renderable array as expected by drupal_render().


To avoid the title is rendered for an entity, you should use a preprocess function for the template file used by the entity, and unset a variable used from the template file for the title. For example, for a node, a module could use the following code.

function mymodule_preprocess_node(&amp;$variables) {
  $variables['title'] = '';
}


Similar code would work for comments, but in that case the function would be mymodule_preprocess_comment().
For taxonomy terms, there isn't a title but there is the term name, which is printed from the template file using the following code.

&lt;?php if (!$page): ?&gt;
  &lt;h2&gt;&lt;a href="&lt;?php print $term_url; ?&gt;"&gt;&lt;?php print $term_name; ?&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;?php endif; ?&gt;


Setting $term_url, and $term_name to an empty string would cause the following HTML output to be printed.

&lt;h2&gt;&lt;a href=""&gt;&lt;/a&gt;&lt;/h2&gt;