I have a Profile2 page where I want to add some HTML into the page title (I want to insert a fontawesome icon). I am using Display Suite to layout the Profile2 page with a custom view mode.

I have succeeded in over-writing the title using the function hook_profile2_view_alter() and drupal_set_title(), but drupal_set_title() uses check_plain, which strips out all the extra html. I tried using hook_preprocess_page, but there is no title variable available. I think this is because Display Suite takes over the title variable, and renames it as label. I also tried the html_title module without any luck, as I'm pretty sure this is because it only works on nodes and not on entities. I also tried hook_preprocesss_profile2 (having first used mymodule_preprocess_entity(&$variables, $hook) to create the function suggestion), but this function doesn't seem to be running on the page. I'm not sure if this is because I'm using display suite or a custom view mode.

Any help much appreciated, as I seem to be running out of options.

2 Answers 2


I solved this by adding the HTML to a custom page template based on the user role and profile. I used the following code to create the template suggestion in the template.php file:

function MYTHEME_preprocess_page(&$variables) {
  global $user;    
    if(arg(0) == 'profile-carer' && in_array('my custom role', $user->roles)) :
      $variables['theme_hook_suggestion'] = 'page__profile_carer_my_custom_role';

I was then able to use the custom template page--profile-carer-my-custom-role.tpl.php based on the page.tpl.php


I have also since found another method explained at Display Suite and HTML node titles

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.