By implementing hook_link_alter()
hook_link_alter in either a custom module or your theme, the.
The code (untested) code would be similar to the following one.:
/**
* Implements hook_link_alter().
*/
function mymodule_link_alter(&$variables) {
if (isset($variables['options']['attributes']['target']) && $variables['options']['attributes']['target'] == '_blank') {
$variables['options']['attributes']['rel'] = 'noopener noreferrer';
}
}
/**
* Implements hook_link_alter().
*/
function MODULE/THEME_link_alter(&$variables) {
if (isset($variables['options']['attributes']['target']) && $variables['options']['attributes']['target'] == '_blank') {
$variables['options']['attributes']['rel'] = 'noopener noreferrer';
}
}