How to add "rel" attributes to all external links throughout the website? I'm trying to add attributes for external links such as the rel=&quot;noopener noreferrer&quot; for all the external links where target=&quot;_blank&quot;. I've tried using modules such as the noreferrer and sel, but neither affect the links in my views.
How can I add rel=&quot;noopener noreferrer&quot; to all links globally where target=&quot;_blank&quot;?
By implementing hook_link_alter in either a custom module or your theme.
The code (untested) would be similar to:
/**
 * Implements hook_link_alter().
 */
function MODULE/THEME_link_alter(&amp;$variables) {
  if (isset($variables['options']['attributes']['target']) &amp;&amp; $variables['options']['attributes']['target'] == '_blank') {
    $variables['options']['attributes']['rel'] = 'noopener noreferrer';
  }
}