Add html markup to a menu link

Public

THis is how to add html markup to any menu link

</> CopyGet raw version
php
  1. // yourmodule-name.module file
  2. use Drupal\Component\Render\FormattableMarkup;
  3. .....
  4.  
  5. function hook_link_alter(&$variables) {
  6. ... your code checking link url and route goes here
  7.  
  8. $markup = new FormattableMarkup('<i class="fa fa-male" aria-hidden="true"></i> @title', array('@title' => $variables['text']));
  9. $variables['text'] = $markup;
  10. }