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 !== ";){
wp_redirect( get_home_url() );
}
else if(is_page(1269) && $ref !== ";){
wp_redirect( get_home_url() );
}
else if(is_page(1825) && $ref !== ";){
wp_redirect( get_home_url() );
}
else if(is_page(1623) && $ref !== ";){
wp_redirect( get_home_url() ); exit();
};