2

Is it possible to somehow get the Nickname to display up at the top of the contacts page?

Is there an preference for this somewhere, or an extension that can do this?

I am on CiviCRM v5.75.0 on WordPress v6.6.1

I am using the Contact Layout Editor by Coleman Watts, which lets me re-organize the contact page layout of different sections, but does not let me move individual fields from one section to another section.

See screenshot of what I am trying to do:nickname

4 Answers 4

3

Without doing any coding you could create a new block using the Contact Layout Editor, and put the Nickname into it. This block could then be put top left of the summary area - this is something I've done already.

1
  • Excellent idea... I like it as an alternative to @coleman answer because it would only be on the contact summary screen.
    – jsherk
    Commented Aug 6 at 21:19
2

Yes, you can do this without any code by updating which fields constitute a "display name". By default Civi uses 4 fields: prefix, first, last & suffix. You can configure this by navigating to "Administer -> Customize Data & Screens -> Display Preferences" and scroll down to "Individual Display Name Format".

Individual Display Name Format

Note that this will affect contact display names everywhere, system-wide, not just on the contact summary screen.

Also note that this change is passive, which means the existing contacts in the database will not have their display names automatically updated when you modify this template. You'll have to edit & re-save every contact with a nickname for it to take effect.

4
  • Ahh... could it be any simplier?
    – jsherk
    Commented Aug 6 at 21:19
  • Hmm... does not seem to work. Even after running clean caches, still nothing extra displays. {contact.individual_prefix}{ }{contact.first_name}{ }{contact.last_name}{ }{contact.individual_suffix}{ }{contact.nick_name}. I even tried just putting some test text in, but that does not show up either.
    – jsherk
    Commented Aug 6 at 21:28
  • The update is passive, e.g. you have to update & save the contact for changes to take effect. Try it out on a single contact. Once you're happy with your template there are a few ways to update every contact in the database, one would be with the api explorer, you could do Individual - Update - Where nick_name IS NOT EMPTY
    – Coleman
    Commented Aug 6 at 22:25
  • Oh I see, this actually updates and saves the nick_name as part of the display_name in db, so it will display that way going forward (but requires a save first).
    – jsherk
    Commented Aug 6 at 23:13
1

So I came up with two solutions of my own.

SOLUTION #1: The simplier one, I implemented from a WordPress plugin using hook_civicrm_contact_get_displayname but you could also impement it from within a civicrm plugin as well. This is fairly simple code and will add the nickname (if it exists) to the end of the display name, everywhere the display name is shown. Here is wordpress plugin code:

require_once(ABSPATH . 'wp-includes/pluggable.php');
add_filter( 'civicrm_contact_get_displayname', 'my_customhook_civicrm_contact_get_displayname', 10, 4  );
function my_customhook_civicrm_contact_get_displayname(&$display_name, $contactId, $dao) {
    $nick_name = trim($dao->nick_name);
    if ($nick_name != "" && ! is_null($nick_name) ) {
        $display_name .= " [$nick_name]";
    }
}

Here is what solution #1 looks like:

solution 1

SOLUTION #2: Is the more complicated one, using the buildForm hook from within a civicrm plugin. It will only display the nickname at the end of the display name within the View Contact Summary pages (at the top of the page). It has the advantage of being able to style the nickname portion different from the rest of the display name so you can make it stand out or be less obtrusive. Here is civicrm plugin code:

function my_customfunctions_civicrm_buildForm($formName, &$form) {
  if ($formName == "CRM_Activity_Form_ActivityLinks") {
    if (strpos($_SERVER['QUERY_STRING'], "page=CiviCRM") !== false && strpos($_SERVER['QUERY_STRING'], "q=civicrm%2Fcontact%2Fview") !== false) { // This checks to make sure its the Contact View page only that I am modifying.
      
      // Add javascript to the page.
      // Need to use   +String.fromCharCode(39)+   to wrap span id in single-quotes.
      // Need to check if the Nickname was already added, otherwise it gets added more than once.
      CRM_Core_Region::instance('page-body')->add( ['script' => "nicknode = document.getElementsByClassName('crm-summary-display_name')[0]; nicknode_text = nicknode.textContent; nickname = document.getElementsByClassName('crm-content crm-contact-nick_name')[0]; nickname_text = nickname.textContent; if (nicknode_text.length > 0 && nickname_text.length > 0) { if (nicknode_text.includes(nickname_text) == false) { nicknode.innerHTML = nicknode_text + ' <span id='+String.fromCharCode(39)+'civicrm-customjs-nickname'+String.fromCharCode(39)+' >[' + nickname_text + ']</span>'; } }" ] );

      // Add some CSS for the newly added span tag to style as-needed.
      CRM_Core_Region::instance('page-body')->add( ['script' => "cj('#civicrm-customjs-nickname').css('font-size', '75%'); cj('#civicrm-customjs-nickname').css('font-style', 'italic');"] );
      
    }
  }
}

Here is what solution #2 looks like (you can style the nickname portion):

solution 2

Of course I came up with the 2nd more complicated solution first, before finding the simpler solution #1.

0

You can implement pagerun hook to over-ride the title

1
  • I looked at pagerun hook, but I think it is the buildform hook that would need to be used.
    – jsherk
    Commented Aug 6 at 21:18

Your Answer

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

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