Font Awesome icons in link field I would like to have a font awesome icon in my link text.

&lt;i class="fa fa-pencil"&gt;&lt;/i&gt;Blogs


Since link fields are generated in LinkGenerator.php, they get escaped.

if (!SafeMarkup::isSafe($variables['text'])) {
  $variables['text'] = Html::escape($variables['text']);
}


There doesn't seem to be any way to bypass this by setting a HTML option to TRUE.

Is there any way to achieve this?
You can define your own template.

For example as inline:

$link = array(
    '#type' =&gt; 'inline_template',
    '#template' =&gt; '&lt;a href="{{ url }}"&gt;&lt;i class="fa {{ fa_icon }}"&gt;&lt;/i&gt;{{ title }}&lt;/a&gt;',
    '#context' =&gt; array(
        'url' =&gt; $url,
        'title' =&gt; $title,
        'fa_icon =&gt; 'fa-pencil',
    ),
  ); 


If you are working on a theme or module you should define a template with its own name like link_fa, so that it can be overridden by other modules or themes.