Skip to content
Advertisement

How to add an icon in local task link ? (Drupal)

I would like to add an icon in the local task links in drupal. Im a newbie.. I have already tried several solutions like :

 $local_tasks['entity.user.canonical']['title'] = '<i> class="icon--search"></i>';

With Markup:

$local_tasks['entity.user.canonical']['title'] = Markup::create('<i class="icon--search"></i>');

And also with an array…

But I found nothing

Advertisement

Answer

There are several ways to add icon.

1> We can preprocess menu local task.

function THEMENAME_preprocess_menu_local_task(&$variables) {
  $variables['link']['#options']['attributes']['class'][] = 'nav-link';
}

Easy way is to use contrib modules like https://www.drupal.org/project/menu_link_attributes

For Drupal7 this tutorial can help https://www.webwash.net/how-to-display-icons-in-drupal-using-icon-api/

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement