Choosing link target behavior in Sanity.io and adding a boolean field

9 replies
Last updated: Jun 26, 2024
How can I choose whether a link opens in a new tab or in the same one?
Jun 26, 2024, 5:25 PM
By adding the
target
attribute to your
a
tags and setting its value to
_blank
will make it so when a user clicks a link it opens in a new tab.
Jun 26, 2024, 5:43 PM
And is there something in the Sanity UI that allows the admin to choose it when editing the content?
Jun 26, 2024, 5:44 PM
Do you already have link object? If so add a boolean field to allow admins to set whether the link should open in a new window or not
Jun 26, 2024, 5:48 PM
Your going to have to modify your link schema to include probably a boolean, then update your serializer to make that rendering decision for you. Its not an "out of the box" Sanity feature
Jun 26, 2024, 5:59 PM
thanx guys
Jun 26, 2024, 6:00 PM
Let’s use greetings like “Hey Everyone,” “Hi, Y’all," or “Hello, Folks” to make sure everyone in the community is included. Please read the Sanity Community Code of Conduct to stay updated on expected communication & behavior in our spaces: https://www.sanity.io/docs/community-code-of-conduct
Jun 26, 2024, 6:00 PM
mean this
Jun 26, 2024, 6:01 PM
Yep, here's a guide from Sanity showing what needs adding to the backend side of your link/description schema - https://www.sanity.io/guides/portable-text-internal-and-external-links#71764b37d9ea
Jun 26, 2024, 6:05 PM
i view this plugin for its useful for other people https://www.sanity.io/plugins/sanity-plugin-link-field
Jun 26, 2024, 6:31 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?