Skip to main content

Drupal 8: Add button class to the read more link of a node

I stumbled across this solution to add attributes to the read more links of a node.

  1. /**
  2.  * Implements template_preprocess_links()
  3.  */
  4. function MYTHEME_preprocess_links(&$variables) {
  5.   $variables['links']['node-readmore']['link']['#options']['attributes']['class'][] = 'button';
  6.   $variables['links']['comment-add']['link']['#options']['attributes']['class'][] = 'button';
  7. }

Thanks: http://drupal.stackexchange.com/a/186323


Comments