Hey all, I’ve got into something above my pay grade, but I still believe it can work… with your help
Essentially I’m creating a **double opt-in** page:
[example.com/preview/]) This page has a form where people enter their details and instead of a confirmation page, they are directed to a page with free training video: [example.com/video/])All this works fine.
I’m stuck at trying to figure out how I can only allow people to go to [example.com/video/]) from the [example.com/preview/]) page.
I have found [useful advice here]), but I can’t get it to work.
This is the code I added to functions.php :
`add_action(‘template_redirect’, function() {`
`// ID of the thank you page`
`if (!is_page(page-id-here)) {`
`return;`
`}`
`// coming from the form, so all is fine`
`if (wp_get_referer() === ‘`[`example.com/preview`]`’) {`
`return;`
`}`
`// we are on thank you page`
`// visitor is not coming from form`
`// so redirect to home`
`wp_redirect(get_home_url());`
`exit;`
`} );`
I’ve tried to write the url for **wp\_get\_referer()** in various ways but it either doesn’t redirect at all or all the time (even when coming from the right page.
I would greatly appreciate any help with this. If anyone knows a better solution to this please feel free to recommend it.
🤞
[ad_2]