Adding `rel` attribute to external links in text block

Hello,

I’m trying to understand how to add a rel="nofollow noopener" attribute to links in the text block when they also have target="_blank" and/or are external links.

I’ve come to the conclusion that links in the text block are rendered in this Vue component of the link mark, with the toDOM() function:

I wanted to ask what are the options to override this behavior, in order to add the rel attribute (if it’s even possible).

Thank you!

Sorry to bump this, does anyone have suggestions? :slight_smile:

This doesn’t help? (link: …) | Kirby CMS

You can use rel and target the same way.

(link: https://forum.getkirby.com text: Kirby Forum rel:nofollow noopener class: btn target:_blank)

results in

<a class="btn" href="https://forum.getkirby.com" rel="nofollow noopener" target="_blank">Kirby Forum</a>

Is that what you’re looking for? You can use HTML in textareas as well.

Hmm actually I’m using blocks with the text block, which should be made with the “writer” component. Links in there are created using the link mark through the panel editor, and it doesn’t seem that you can add additional attributes there.

Thanks for the answer!

Yes, that doesn’t work with writer fields. Is it an option to change the blocktype to “text” or “textarea”? In the template the following seem to work as i mentioned.

<?= $page->writer()->kt();?>
<?= $page->textarea()->kt();?>

where “writer” and “textarea” are the fieldnames.

But i guess you’re using the default blocktypes, right? Try using the “markdown” blocktype. It allows using HTML, Markdown and Kirbytext, so

(link: https://forum.getkirby.com text: Kirby Forum rel:nofollow noopener class: btn target:_blank)

will end up in the mentioned HTML code. Disadvantage: it’s not WYSIWYG.

Or you could create a custom blocktype or plugin, but that is probably too much. Probably someone else has another idea.

Hi @mcont, I’m trying to do the same thing as you or very similar: I want to add the option to add a rel= attribute through a dedicated field in the link dialogs (from writer and textarea toolbars).

Have you found a way to solve your problem?

Hi, no, I didn’t find solutions.

What I then discovered (and I consider that an acceptable solution for my use case) is that modern browsers treat target="_blank" links as if they also had the rel="noopener" attribute, so the security issues deriving from not having noopener don’t seem to be an issue anymore.

It’s still not a solution if you need other rel values though, and I’m afraid I can’t really help on that.

All right. That does not cover my use case indeed as I need real values for SEO (adding nofollow to some links). I’m trying to think of something to cover this. Not there yet.

Thanks for the answer

1 Like