Skip to content

hook_civicrm_contact_get_displayname

Summary

This hook is called when retrieving the display name of a contact, allowing you to alter it and return a custom display name.

Definition

civicrm_contact_get_displayname(&$display_name, $contactId, $dao)

Parameters

  • &$display_name - the current display name, passed by reference. Change this to alter the display_name.
  • $contactId - Contact ID
  • $dao - A DAO object containing contact fields + primary email field as "email".

Returns

  • null

Example

Use cases: - You want to show who is a manager of an organisation but you don't want to store this in the database. - You want to indicate if the contact is deceased. - Below an example of showing the contact ID after the display name:

function myextension_civicrm_contact_get_displayname(&$display_name, $contactId, $dao) {
  $display_name = $display_name . ' - ' . $contactId;
}