How to add class to content field link in Drupal 8 / 9

0
(0)

Example How to add custom class to content field link in Drupal 8 & 9.

function THEMENAME_preprocess_field(&$variables, $hook) {
  $element = $variables['element'];
  if ($element['#field_name'] == 'field_link') {
    $variables['items'][0]['content']['#options']['attributes']['class'][] = 'btn  btn-danger';
  }
}

Similar Posts:

862

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Scroll to Top