I have a CMS set up for resources and if a CMS item has a specific link field filled out I would like the page to automatically follow that link on load.
So if I click on a collection item in a collection list on a page, when it goes to that collection item if it has the link field “press link” filled out I want it to automatically click and follow that link on the page load.
It’s probably better to implement that in the collection list itself.
You can probably just wrap your collection item in a link block and bind it to your link field. When it’s empty, nothing will happen. When it’s not empty, the browser would nav to your URL.
Or, you can have two version that are different, and use conditional visibility ( link is set / link is not set ) to show only one version of that item.
... collection item
div ( for no link )
... show your content
div ( has link )
a href = your link
... show your content
Otherwise, you can do it on the collection page using JS.
In the collection page’s before-/head code
<script>
const link = ""; // a value will be inserted here externally
if (link) {
window.location.href = link;
}
</script>
Then inside of those “” you’d +Add field your link.
I think this is a but messier because;
User will probably see a flash as it navigates and then redirects
These pages are still in the sitemap
Google will still try to crawl them, and get redirects
GSC will complain, your reports will get messy
But that may be what you want, if you’re wanting to be able to hand out links like mysite.com/resource/some-cool-thing
And then be able to change where that actually points later for each resource.
If it were as simple as only having one possible link to follow/not follow I’d do it on the collection list - but since there are a lot of conditional items in my collection page I’ll be using the second option. Thank you very much for your help!