Skip to content

Link label & target customization#15983

Merged
brandonkelly merged 2 commits into5.5from
feature/cms-1345-link-label-target-customization
Oct 30, 2024
Merged

Link label & target customization#15983
brandonkelly merged 2 commits into5.5from
feature/cms-1345-link-label-target-customization

Conversation

@brandonkelly
Copy link
Copy Markdown
Member

@brandonkelly brandonkelly commented Oct 30, 2024

Description

Adds new “Show the ‘Label’ field” and “Show the ‘Open in a new tab’ field” settings to Link fields.

The new Link field settings

If either setting is enabled, the link field + label/target settings will be displayed with a light border surrounding them:

A Link field with both new settings activated

craft\fields\data\LinkData::getLink() will include the custom label and target="_blank" in its returned <a> tag when appropriate.

LinkData::getLabel() will return the custom label by default, if set. You can also now pass true to force the custom label to be returned or null if not; or false to force the default (link type-provided) label to be returned, ignoring the custom one.

The link target (null or '_blank') can be accessed via LinkData::$target.

Related issues

@linear
Copy link
Copy Markdown

linear Bot commented Oct 30, 2024

[ci skip]
@brandonkelly brandonkelly merged commit 713ba7a into 5.5 Oct 30, 2024
@brandonkelly brandonkelly deleted the feature/cms-1345-link-label-target-customization branch October 30, 2024 20:45
@thisisjamessmith
Copy link
Copy Markdown

thisisjamessmith commented Jun 10, 2025

Just a quick note that I think the docs have the true/false parameter of getLabel() the wrong way round - might be good to get that corrected:

https://craftcms.com/docs/5.x/reference/field-types/link.html -

This is the default behavior when using a link’s link property. If you need to retrieve the label as it was entered (bypassing Craft’s internal fallback logic), use link.getLabel(false).

@AugustMiller
Copy link
Copy Markdown
Contributor

@thisisjamessmith Good catch—just pushed up a few edits to that paragraph! 💞

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants