If the form is redirecting from one page only, you can easily use wp_get_referer()
to check for it and if not, redirect.
add_action('template_redirect', function() {
// ID of the thank you page
if (!is_page(12345)) {
return;
}
// coming from the form, so all is fine
if (wp_get_referer() === 'URL_OF_FORM') {
return;
}
// we are on thank you page
// visitor is not coming from form
// so redirect to home
wp_redirect(get_home_url());
exit;
} );
Related Posts:
- Redirect Restricted Page to 404
- Redirect user to original url after login?
- Redirect to dashboard after login
- Site redirects to wrong url when saving settings
- Redirect blog page to latest post?
- Index in root, wordpress in subdirectory
- WordPress overriding actual subdirectories
- Redirect to “All Posts” after post update or publish in Block Editor
- Redirect user after login/registration globally
- How to redirect only if page doesn’t exists
- how to do logout redirect to current url
- htaccess redirect – directory and subpages to a single page
- Plugin for conditional redirect
- https multiple redirects
- Redirects from Tumblr to new WP
- How to modify the Register link in the login page?
- WordPress redirecting to 127.0.0.1 when accessing the site from a remote device
- Changing “Lost Password Email Link” to custom password reset page
- Redirect a page id url but not the page slug
- Redirect based on parameter in url
- Stop wordpress redirecting www to non-www
- WordPress Global Redirect
- Why does wp_redirect strip out %0A (url encoded new line character) and how do I make it stop?
- htaccess redirect – replace special character
- Redirect Logged In User if page is wp-login.php and $_Get[‘level’] = X
- Right hook to redirect frontend visitors while respecting rest api plugins to run first?
- Redirect loop after changing nameserver [closed]
- Is it possible to incorporate username in a login redirect?
- How to make wordpress folder (/wordpress) redirect to /?
- Changing domain
- How to redirect on login to a specific page if a specific meta user is empty
- Redirecting amp url to non amp url
- How To Redirect /url.html to /url?
- Remove #wpcf7-f2450-o1 with Contact form 7 redirect [closed]
- Redirecting deleted posts url to another WordPress install
- Redirect – remove custom query string
- 301 redirect from old URL structur to new
- Redirect each user to specific pages based on their role
- How to fix too many redirects when enabling SSL for site?
- Custom redirect user after login based on metadata
- wp_redirect () doesn’t work in nginx?
- Add Username to URL for redirect
- Log out and redirect to different URL
- How to get better performance for redirect from domain.tld/35 to domain.tld/full-permalink?
- Redirect deleted page URL ?p=xxxx
- Have WordPress post redirect to url when accesed from iPad (Safari)
- I want to resolve Redirect Chain [closed]
- How to fix URL with pageid example /?p= too many redirection error
- Conditional redirect to several pages
- Adding query string parameters to URL with same name as custom post type gives 404 error
- Display Freebie Page Content only if Referrer is from Form Page
- Dynamic redirect
- simple wordpress form redirection
- Redirect to home if page doesn’t exists [duplicate]
- Redirect all links form a category to new links on new category
- My redirect URL doesn’t show any pages on my website [closed]
- Forced Redirect on a server migration
- Site Address and WordPress Address settings when using a load balancer
- Cannot install wordpress, /wp-admin/install.php, inproper redirection [closed]
- Prevent “/login” to redirect to “/wp-login”
- How to redirect logged out users to specific page?
- Redirect certain pages if user logged in
- Login redirect shows white page in firefox
- Redirect to post_id?
- wp_login_form redirect
- Date based redirects of posts that no longer exist
- How can I disable redirect domains?
- When i try to enter subdomain i’m redirected to main domain
- redirect wordpress post to new subfolder site on same domain
- 301 all old pages to new location
- Use a 301 to Redirect any 404 from at the blog post level to the blog archive
- How do I share a site only to one User at the time? Please help 🥺🙌
- Re-Direct ALL Users to the Home Page IF not logged in
- Author Archive Page redirecting issue
- Understanding Redirects
- Random redirect to wp-admin/install.php
- Changing auth_redirect() page
- How to redirect returning users who previously logged in?
- Page editing in backend redirecting to 404 page not found with url /post.php
- wordpress redirect error in xampp
- Swapping current old site to new WordPress site – need to check I’m doing it right
- how redirect users to custom login page when user comment must “login to reply” is clicked?
- Redirect User to Specific Page
- Allow GET request on certain page
- .htaccess redirect for old subfolder installation to new subfolder installation and https
- PHP Mistake – Whats wrong here?
- On login redirect to different homepage if user is using a mobile
- WordPress update 4.4.1 redirect loop
- Redirecting Issue
- Redirect user to login and then to page where they came from
- htaccess and redirect to new url using regex
- redirect attachment page to category page
- 301 redirect for wordpress permarlink
- Google PageSpeed: Avoid landing page redirects?
- Redirect to 404.php from single.php
- How to make my homepage automatically redirect to an external website?
- How to Redirect Url to homepage?
- 404 Not Found with All Cloaking plugins
- Stopping media file redirects
- How to find out what is causing redirect of static content?