I have a thank you page on my website and I don’t want anyone can access it directly so I use the below code and it working.
add_action('template_redirect', function() {
// ID of the thank you page
if (!is_page(947)) { //id of page
return;
}
// coming from the form, so all is fine
if (wp_get_referer() === get_site_url().'/contact-us/') {
return;
}
// we are on thank you page
// visitor is not coming from form
// so redirect to home
wp_redirect(get_home_url());
exit;
});
Now, what I am doing, I have one more form on my single post and once the user submits the form then it will redirect to the thank you page but it’s not going because I added the above code on my function.php
.
So anyone knows how to access the thank you page from the single post?