Question

I have parent pages which are downloadable resources. On these pages, people will fill in a form and then be redirected to a thank you page.

The thank you pages are child pages.

I would like to block direct access to those child pages and only allow access if people were redirected from the parent pages.

I found some code online but this would means that I need to edit this code for every resource I add. I would like to code to only allow access if redirected from the parent page.

How can I achieve this?

function wpse15677455_redirect() {
$ref = wp_get_referer(); if (is_page(1911) &&$ref !== "https://www.example.com/contact"){
wp_redirect( get_home_url() );
}
else if(is_page(1269) && $ref !== "https://www.example.com/contact-form-2"){ wp_redirect( get_home_url() ); } else if(is_page(1825) &&$ref !== "https://www.example.com/contact-form-3"){
wp_redirect( get_home_url() );
}
else if(is_page(1623) && \$ref !== "https://www.example.com/contact-form-4"){
wp_redirect( get_home_url() ); exit();


};

0
2 years 2020-10-25T10:10:20-05:00 0 Answers 9 views 0