Problem/Motivation

Link Purpose adds visually hidden text such as “opens in a new tab” to links.
Search engines may include this text in result snippets, making them less readable.

Steps to reproduce

  1. Enable Link Purpose.
  2. Add a link that opens in a new tab.
  3. Let the page be indexed.
  4. The hidden link-purpose text may appear in the search snippet.

Proposed resolution

Add data-nosnippet to the generated element with the class
link-purpose-text.

<span class="link-purpose-text" data-nosnippet>
  Opens in a new tab
</span>

This should keep the text available to assistive technologies while excluding it
from supported search result snippets.

Remaining tasks

  • Add the attribute.
  • Add or update tests.
  • Document the behaviour.

User interface changes

None.

API changes

None.

Data model changes

None.

CommentFileSizeAuthor
#3 linkpurpose.patch33.23 KBben-ro

Comments

kairay created an issue. See original summary.

itmaybejj’s picture

Assigned: Unassigned » itmaybejj

Good idea

ben-ro’s picture

StatusFileSize
new33.23 KB

Hey @itmaybejj,

we hit this on a project and tried to fix it there, so I've pushed our change as MR on Github since the source of truth for this module appears to be there.

The actual fix is one line. Everything else in the diff is the rebuilt bundle and updated documentation.

Tested against Drupal 11.3: The data-nosnippet attribute is added to the DOM as proposed.

Happy to restructure if that's easier for you or create a MR on Gitlab.

The fix in our project is from @roxbozbyaw

  • itmaybejj committed 658aa009 on 1.0.x
    feat: #3610931 Prevent visually hidden link-purpose text from appearing...
itmaybejj’s picture

Status: Active » Fixed

Wonderful; that was exactly what what I needed to do.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.